【发布时间】:2021-04-27 05:43:35
【问题描述】:
我想在用户按下错误按钮时输出一些句子,然后在他们回答错误并退出进程时使用 tkinter 模块退出(比如说“白痴”或其他东西)。但是,command=lambda: 只支持一个动作,当我添加多行时,python 解释器会输出错误。有没有办法对 tkinter 制作的窗口执行两个或多个操作?
这是代码的一部分,我希望代码输出 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()
【问题讨论】:
-
只需创建一个新函数并在函数内调用任何你想要的东西。
标签: python tkinter game-development