Python 有没有办法先输出一个句子,然后在tkinter中退出

Python 有没有办法先输出一个句子,然后在tkinter中退出,python,tkinter,game-development,Python,Tkinter,Game Development,我想在用户按下错误的按钮时输出一些句子,然后在他们回答错误并退出流程时使用tkinter模块退出(比如说“白痴”之类的)。但是,command=lambda:仅支持一个操作,当我添加多行时,python解释器将输出一个错误。有没有办法对tkinter制作的窗口执行两个或多个操作? 这是代码的一部分,我希望代码输出self.correspondingBehavior部分,然后退出 class Q3(tk.Frame): def __init__(self, parent, controll

我想在用户按下错误的按钮时输出一些句子,然后在他们回答错误并退出流程时使用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()

可以使用lambda在command属性中给出多个命令(可以调用多个函数)。为此,您可以使用列表

例如,
command=lambda:[root2.destroy(),next_step()]


这将首先销毁并退出root2窗口。然后也调用next_step()函数。

只需创建一个新函数并在函数中调用所需的任何函数。不建议这样做,最好只定义另一个函数来调用这两个函数,而不是使用lambdaIt。这与使用
def function1():
def function2()类似:
在开头添加两个不同的操作,并使用
命令:function1(),function2()