0
以外的窗口內的所有內容我想在按下GameButton按鈕時銷燬窗口根內的所有內容,但是我希望發生其他事情,所以唯一的方法是爲按鈕運行一個功能。當我在主類之外執行self.destroy時,沒有東西被刪除,是否有解決方法?在下面的代碼中破壞函數Tkinter
from PIL import Image, ImageTk
from Tkinter import Tk, Label, BOTH,W, N, E, S, Entry, Text, INSERT, Toplevel
from ttk import Frame, Style, Button, Label
import Tkinter
import Callingwordlist
difficulty = ""
class MainMenuUI(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.parent.title("Type!")
self.pack(fill=BOTH, expand=1)
style = Style()
style.configure("TFrame", background="black")
Logo = Image.open("Type!.png")
TypeLogo = ImageTk.PhotoImage(Logo)
label1 = Label(self, image=TypeLogo)
label1.image = TypeLogo
label1.place(x=342,y=80)
label1.pack()
self.pack(fill=BOTH, expand=1)
GameButton = Button(self, text="Main Game", command=lambda: main2(self.parent,self))
GameButton.pack()
GameButton.place(x=344,y=200,height = 80,width = 176)
TutorialButton = Button(self,text="Tutorial Level")
TutorialButton.pack()
TutorialButton.place(x=344, y=300 ,height = 80,width = 176)
quitbutton = Button(self, text= "Quit",command=self.parent.destroy)
quitbutton.place(x=344, y=400,height = 80,width = 176)
def main2(root,self):
self.destroy
app = MainGameUI(root)
root.mainloop()
class MainGameUI(root):
....
def main():
root = Tk()
root.geometry("860x640+300+300")
app = MainMenuUI(root)
root.mainloop()
if __name__ == '__main__':
main()
感謝您的建議,現在一切都正常工作,並刪除root.mainloop減少了我的代碼 – Dolan