有没有办法先输出一个句子然后在tkinter中退出
Is there a way to output a sentence first then exit in tkinter
我想在用户按下错误的按钮时输出一些句子,然后在他们回答错误并退出进程时使用 tkinter 模块退出(比如说“白痴”之类的)。但是,command=lambda:
只支持一个动作,当我添加多行时,python 解释器会输出错误。有什么方法可以为 tkinter 制作的 windows 执行两个或更多操作?
这是代码的一部分,我希望代码输出 self.correspondingBehavior 部分然后退出。
class Q3(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="MCQ test!!! Question 3: Organic chemistry is the study of the compounds that "
"make up living organisms. All organic molecules contain:", font=LARGE_FONT)
label.pack(pady=10, padx=10)
button1 = tk.Button(self, text="Carbon only",
command=lambda:self.correspondingBehavior('Wrong...check your '
'notes and try '
'again.'))
button1.pack()
button2 = tk.Button(self, text="Carbon and nitrogen",
command=lambda:self.correspondingBehavior('Wrong...check your '
'notes and try '
'again.'))
button2.pack()
button3 = tk.Button(self, text="Carbon and hydrogen",
command=lambda: controller.show_frame(Q4))
button3.pack()
button4 = tk.Button(self, text="Quit", command=lambda: controller.destroy())
button4.pack()
您可以使用 lambda 在命令属性中给出多个命令(您可以调用多个函数)。为此,您可以使用列表。
例如,command=lambda:[root2.destroy(), next_step()]
这将首先销毁并退出 root2 window。然后还调用 next_step() 函数。
我想在用户按下错误的按钮时输出一些句子,然后在他们回答错误并退出进程时使用 tkinter 模块退出(比如说“白痴”之类的)。但是,command=lambda:
只支持一个动作,当我添加多行时,python 解释器会输出错误。有什么方法可以为 tkinter 制作的 windows 执行两个或更多操作?
这是代码的一部分,我希望代码输出 self.correspondingBehavior 部分然后退出。
class Q3(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="MCQ test!!! Question 3: Organic chemistry is the study of the compounds that "
"make up living organisms. All organic molecules contain:", font=LARGE_FONT)
label.pack(pady=10, padx=10)
button1 = tk.Button(self, text="Carbon only",
command=lambda:self.correspondingBehavior('Wrong...check your '
'notes and try '
'again.'))
button1.pack()
button2 = tk.Button(self, text="Carbon and nitrogen",
command=lambda:self.correspondingBehavior('Wrong...check your '
'notes and try '
'again.'))
button2.pack()
button3 = tk.Button(self, text="Carbon and hydrogen",
command=lambda: controller.show_frame(Q4))
button3.pack()
button4 = tk.Button(self, text="Quit", command=lambda: controller.destroy())
button4.pack()
您可以使用 lambda 在命令属性中给出多个命令(您可以调用多个函数)。为此,您可以使用列表。
例如,command=lambda:[root2.destroy(), next_step()]
这将首先销毁并退出 root2 window。然后还调用 next_step() 函数。