我不能破坏顶层(Tkinter,python)
在我的程序中
1)在开始时用户按下按钮并出现顶层
2)在顶层有更多的小部件和一个按钮
3)当用户按下这个(第二个)按钮时,函数(name_of_toplevel.destroy())开始工作
4)但是终端写给我“NameError:未定义全局名称'name_of_toplevel'”
5)但它确实被定义了!
6) 按钮通过“绑定”方法与功能绑定
节目正文:
from Tkinter import *
def Begin(event):
okno.destroy()
def QuitAll(event):
exit(0)
def OpenOkno(event):
#print "<ButtonRelease-1> really works! Horray!"
okno = Toplevel()
okno.title('Question')
okno.geometry('700x300')
Sign = Label(okno,text = 'Quit the program?', font = 'Arial 17')
Sign.grid(row = 2, column = 3)
OK = Button(okno, text = 'YES', bg = 'yellow', fg = 'blue', font = 'Arial 17')
OK.grid(row = 4, column = 2)
OK.bind("<ButtonRelease-1>",QuitAll)
NO = Button(okno, text = 'NO', bg = 'yellow', fg = 'blue', font = 'Arial 17')
NO.grid(row = 4, column = 4)
NO.bind("<ButtonRelease-1>",Begin)
root = Tk() # main window 'program_on_Python'
root.title('Program_on_Python')
root.geometry('400x600')
knpk = Button(root, text = 'click here!', width = 30, height = 5, bg = 'yellow', fg = 'blue', font = 'Arial 17')
knpk.grid(row = 2, column = 2)
knpk.bind("<ButtonRelease-1>",OpenOkno)
root.mainloop()
如果可以,请你帮助我