使用tkinter可以很方便地创建二级和三级弹窗。以下是一个示例代码,展示如何实现这两个级别的弹窗: ```python import tkinter as tk def create_second_level_popup(): second_level_popup = tk.Toplevel(root) second_level_popup.title("Second Level Popup") second_level_popup.geometry("200x100") label = tk.Label(second_level_popup, text="This is a second-level popup") label.pack() button = tk.Button(second_level_popup, text="Close", command=second_level_popup.destroy) button.pack() def create_third_level_popup(): third_level_popup = tk.Toplevel(second_level_popup) third_level_popup.title("Third Level Popup") third_level_popup.geometry("200x100") label = tk.Label(third_level_popup, text="This is a third-level popup") label.pack() button = tk.Button(third_level_popup, text="Close", command=third_level_popup.destroy) button.pack() root = tk.Tk() root.title("Main Window") root.geometry("200x100") button1 = tk.Button(root, text="Open Second Level Popup", command=create_second_level_popup) button1.pack() button2 = tk.Button(root, text="Open Third Level Popup", command=create_third_level_popup) button2.pack() root.mainloop() ``` 在这个示例中,我们首先创建了一个主窗口(main window),然后创建了两个按钮。当点击第一个按钮时,会创建一个二级弹窗(second-level popup),当点击第二个按钮时,会创建一个三级弹窗(third-level popup)。 注意,在创建三级弹窗时,我们使用了`Toplevel`的构造函数的第一个参数,将其设置为二级弹窗,这样就实现了一个三级的弹窗。 每个弹窗都有自己的、尺寸以及关闭按钮。当点击关闭按钮时,弹窗会被销毁。 [2024-05-22 11:01:15 | AI写代码神器 | 1069点数解答]