【发布时间】:2014-05-03 04:50:59
【问题描述】:
我正在使用 tkinter 制作一个测验应用程序,我希望每个问题都在一个新窗口中,但是在我创建一个新窗口之后,我无法弄清楚如何销毁前一个窗口。这是我的代码的粗略简化摘录:
from tkinter import *
class q1:
def __init__(self, master):
self.master = master
Label(self.master, text='What is 3 + 3?').grid()
self.option_1 = Button(self.master, text='5', command = self.incorrect)
self.option_1.grid()
self.option_2 = Button(self.master, text='6', command = self.correct)
self.option_2.grid()
def correct(self):
self.option_1.config(state=DISABLED)
self.option_2.config(state=DISABLED)
Label(self.master, text='Correct').grid()
Button(self.master, text='Next Question', command = self.nextq).grid()
def incorrect(self):
self.option_1.config(state=DISABLED)
self.option_2.config(state=DISABLED)
Label(self.master, text='Incorrect').grid()
Button(self.master, text='Next Question', command = self.nextq).grid()
def nextq(self):
q2(Toplevel(self.master))
class q2:
def __init__(self, master):
self.master = master
Label(self.master, text='Question 2').grid()
def window():
root = Tk()
q1(root)
root.mainloop()
if __name__ == '__main__':
window()
【问题讨论】:
标签: python python-3.x tkinter