Jump to content


Photo

__init__() Takes From 1 To 3 Positional Arguments But 4 Were Given


  • Please log in to reply
1 reply to this topic

#1 Mimi96

Mimi96

    New Member

  • Members
  • Pip
  • 2 posts

Posted 07 October 2014 - 08:54 AM

Hi , everyone. I have a problem with the last code in chapter 10. Here is my sound_panel.py
from tkinter import*
import pygame.mixer
class SoundPanel(Frame):
    def _init_(self, app, mixer, sound_file):
        
        Frame._init_(self, app)
        self.track = mixer.Sound(sound_file)
        self.track_playing = IntVar()
        Checkbuttton(self, variable = self.track_playing, command = self.track_toggle, text = sound_file).pack(side = LEFT)

        self.volume = DoubleVar()
        self.volume.set(self.track.get_volume())
        Scale(self, variable = self.volume, from_ = 0.0, to = 1.0, resolution = 0.1, command = self.change_volume, label = "Volume", orient = HORIZONTAL).pack()

    def track_toggle(self):
        if self.track_playing.get() == 1:
            self.track.play(loops = -1)
        else:
            self.track.stop()


    def change_volume(self, v):
        self.track.set_volume(self.volume.get())


And this is my hfmix.py
from tkinter import*
from sound_panel import*
import pygame.mixer
import os
app = Tk()
app.title("Head First Mix")
mixer = pygame.mixer
mixer.init()

dirList = os.listdir(".")
for fname in dirList:
    if fname.endswith(".wav"):
        panel = SoundPanel(app, mixer, fname)
        panel.pack()

def shutdown():
    mixer.stop()
    app.destroy()

app.protocol("WM_DELETE_WINDOW", shutdown)
app.mainloop()

When I try to run the program, the following message appears:

Traceback (most recent call last):
File "C:/Users/mishka/Desktop/Python Projects/hfmix.pyw", line 13, in <module>
panel = SoundPanel(app, mixer, fname)
TypeError: __init__() takes from 1 to 3 positional arguments but 4 were given


Can you help me? :)

#2 #TM#

#TM#

    Active Member

  • Members
  • PipPipPip
  • 91 posts
  • Gender:Not Telling

Posted 12 October 2014 - 08:45 AM

Hi Mimi96, there are some syntax mistakes only.


Hi , everyone. I have a problem with the last code in chapter 10. Here is my sound_panel.py

from tkinter import* # Problem here keep the * (star) separated from import in both the scripts.
import pygame.mixer
class SoundPanel(Frame):
    def _init_(self, app, mixer, sound_file): # ... and here it is not "_init_" but "__init__" (double underscore)
        
        Frame._init_(self, app) # and here the same.

Keep the * sign (star sign) separated by a space from the import in both the script files and change the _init_ to __init__ (NOT single but double underscore)

:) B)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users