I have the following code:
import mp3play
try:
from Tkinter import *
except ImportError:
from tkinter import *
root = Tk()
def playMusic(root):
filename = r'D:\My Documents\School Work\A2 Computing\Project\Westerado.mp3'
mp3 = mp3play.load(filename)
mp3.play()
# Declaring the buttons
button1 = Button(text="Play", fg="Black", height=1, width=7, command= playMusic)
and some more which is irrelevant to this error, however when I run the program the GUI wil show up as normal, except that when I click button1 I get the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "D:\Python2.7\lib\lib-tk\Tkinter.py", line 1532, in __call__
return self.func(*args)
TypeError: playMusic() takes exactly 1 argument (0 given)
I have not done much work with Python functions and button commands and therefore am uncertain of what has gone wrong although I do believe that the function playMusic 's parameter(s) are incorrect.
What do I need to change here in order to get this working? I know that if I take out the def playMusic(root): altogether, then when I run to code the music will play as it should. But it is the button click command that is incorrect.
EDIT -
I have switched to def play_music():, now I do not get any error when I click the button. Instead, the program button will look like it has frozen being clicked down as if it is trying to do something but nothing will come of it.
commands don't get passed any arguments - switch todef play_music():(note also style-guide compliant name!)def play_music():, now I do not get any error when I click the button. Instead, the program button will look like it has frozen being clicked down as if it is trying to do something but nothing will come of it..play()method never returns.import mp3playfilename = r'D:\My Documents\School Work\A2 Computing\Project\Westerado.mp3' mp3 = mp3play.load(filename) mp3.play()obviously the file path will differ for each person. The documentation for mp3play can be found here: code.google.com/p/mp3play/wiki/Examples