【发布时间】:2014-03-06 10:35:41
【问题描述】:
在下面的代码中,我想在按下 GameButton 按钮时销毁窗口根目录内的所有内容,但是我希望发生其他事情,因此唯一的方法是让按钮运行一个函数。当我在主类之外执行 self.destroy 时,什么都没有被删除,有什么办法解决这个问题吗?
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()
【问题讨论】:
标签: python function tkinter window destroy