Найти - Пользователи
Полная версия: Проблема с отображением кнопок в Tkinter, python GUI
Начало » Центр помощи » Проблема с отображением кнопок в Tkinter, python GUI
1
tempkoder12
 #imports%%%%%%%%%%%
import os
import tkinter
from pygame import mixer
from tkinter import *
from tkinter import filedialog
from tkinter.filedialog import askopenfilename
#%%%%%%%%%%%%%%%%%%%
MGI = tkinter.Tk()
MGI.title("LISTER V 0.0.3")
def stop_treak(filename):
	mixer.music.pause(filename)
def playmusic(filename):
	mixer.init()
	mixer.music.load(filename)
	mixer.music.play()
	stop_icon=PhotoImage(file ="stop.png")
	stop_button =Button(MGI, image = stop_icon, command = stop_treak(filename))
	stop_button.pack()
def filedialog():
	filename =  askopenfilename()
	playmusic(filename)
def stop_treak():
	pygame.mixer.music.stop()
folder_icon=PhotoImage(file="dwsa.png")
 
select_dirctory = Button(MGI, image = folder_icon, command = filedialog)
select_dirctory.pack()
MGI.mainloop()



По задумке когда включается трек должна создаваться кнопка стоп и при нажатии на неё должен останавливаться трек но вместо этого появляется ошибка


ошибка:
Exception in Tkinter callback
Traceback (most recent call last):
File “C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py”, line 1705, in __call__
return self.func(*args)
File “SUPERSAMPLEPLAYER.py”, line 30, in filedialog
playmusic(filename)
File “SUPERSAMPLEPLAYER.py”, line 21, in playmusic
stop_button =Button(MGI, image = stop_icon, command = stop_treak(filename))
TypeError: stop_treak() takes 0 positional arguments but 1 was given


JOHN_16
UnboundLocalError: local variable ‘stop_treak’ referenced before assignment
Вам говорят что пременная используется прежде чем была определена.
И это действительно так. Кнопку вы создаете на 2 стрчоки раньше чем определяете функцию.
Сперва нужно определить функцию, а потом ею пользоваться.
tempkoder12
Как это исправить ?
tempkoder12
File “C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py”, line 1705, in __call__
return self.func(*args)
File “SUPERSAMPLEPLAYER.py”, line 30, in filedialog
playmusic(filename)
File “SUPERSAMPLEPLAYER.py”, line 21, in playmusic
stop_button =Button(MGI, image = stop_icon, command = stop_treak(filename))
TypeError: stop_treak() takes 0 positional arguments but 1 was given
JOHN_16
если вы не читаете что вам пишут, то я не в силах вам помочь
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB