我想教自己的Python这样的东西可能是一个愚蠢的问题,但是这已经快把我逼疯了几天道歉。我看了看这里的同一主题的其他问题,但似乎仍然没有能够得到这个工作。关闭一个Toplevel的窗口的Tkinter
我创建了一个顶层窗口,要求提示用户,并希望该窗口当用户按自己选择的按钮关闭。这就是问题的所在,我不能让它关闭为爱或金钱。我的代码包含在下面。
感谢这么多的帮助。
from Tkinter import *
root = Tk()
board = Frame(root)
board.pack()
square = "Chat"
cost = 2000
class buyPrompt:
def __init__(self):
pop = Toplevel()
pop.title("Purchase Square")
Msg = Message(pop, text = "Would you like to purchase %s for %d" % (square, cost))
Msg.pack()
self.yes = Button(pop, text = "Yes", command = self.yesButton)
self.yes.pack(side = LEFT)
self.no = Button(pop, text = "No", command = self.noButton)
self.no.pack(side = RIGHT)
pop.mainloop()
def yesButton(self):
return True
pop.destroy
def noButton(self):
return False
我试着做pop.destroy
的很多不同的方法,但似乎没有工作,事情我已经试过的;
pop.destroy()
pop.destroy
pop.exit()
pop.exit
谢谢
非常感谢您提供这样一个清晰简洁的答案右腿,这已经解决了我的问题,并在调用方法时帮助我了解将来的知识。很好的答案,也很快,再次感谢 – Shallon