【发布时间】:2022-08-03 05:04:59
【问题描述】:
当我执行此代码时
gui = Tk()
def GUI():
global gui
gui.geometry(\"1920x1080\")
gui.mainloop()
menu()
def menu():
global mdb
mdb = Button(gui, text= \"DOWNLOAD\", command = txt_input , width = \"40\", height = \"10\")
mdb.place(x = 925, y= 470)
mdb.pack
gui.mainloop()
def txt_input():
## zapise tkinter zalezitosti ako globalne
global menu,itxt,itxtb
##odstrani to tlacitko DOWNLOAD ktore zobrazovalo entry a dalsie tlacitko
mdb.pack_forget()
##vytvori to tlacitko ktore vrati cloveka do menu
menu = Button(gui, text= \"MENU\", command = backtomenu)
menu.pack()
##vytvori policko na zadavanie youtube url
itxt= Entry(gui)
itxt.place(x= 860, y=440, width= 200, height=24)
itxt.pack
##vytvori tlacitko ktore spusti get_entry funkciu
itxtb= Button(gui, text= \"DOWNLOAD\", command = get_entry)
itxtb.place(x = 925, y= 470)
itxtb.pack
gui.mainloop()
##ziska text ktori bol zadany do itxt
def get_entry():
global y
y = itxt.get()
##zavola funkciu na stiahnutie audia
download_audio()
##odstrani veci ktore boli na okne a vrati cloveka do menu
def backtomenu():
menu()
itxt.destroy
itxtb.destroy
menu.destroy
gui.mainloop()
GUI()
但是当我执行它时,我得到了这个错误
Traceback (most recent call last):
File \"D:\\projektdavidnemecek\\YOUTUBE-MP3-DOWNLOADER AND PLAYER-DavidNemecek.py\", line 110, in <module>
GUI()
File \"D:\\projektdavidnemecek\\YOUTUBE-MP3-DOWNLOADER AND PLAYER-DavidNemecek.py\", line 53, in GUI
menu()
File \"D:\\projektdavidnemecek\\YOUTUBE-MP3-DOWNLOADER AND PLAYER-DavidNemecek.py\", line 58, in menu
mdb = Button(gui, text= \"DOWNLOAD\", command = txt_input , width = \"40\", height = \"10\")
File \"C:\\Users\\FRESH DUFF\\AppData\\Local\\Programs\\Python\\Python39\\lib\\tkinter\\__init__.py\", line 2650, in __init__
Widget.__init__(self, master, \'button\', cnf, kw)
File \"C:\\Users\\FRESH DUFF\\AppData\\Local\\Programs\\Python\\Python39\\lib\\tkinter\\__init__.py\", line 2572, in __init__
self.tk.call(
_tkinter.TclError: can\'t invoke \"button\" command: application has been destroyed
我不知道如何修复它,我无法在互联网上找到任何修复程序。如果我将 GUI() 函数与 menu() 函数合并,它决定工作。