|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
各位大神 小甲鱼讲的tkinter这个东西,每次点击按钮都能弹出一个对话框,能否让他每次只独立弹出一个对话框。当第二个对话框打开时,前面那个对话框关闭呢?
from tkinter import *
root = Tk()
def create():
top = Toplevel()
top.title("FishC Demo")
msg = Message(top, text="I love FishC.com!")
msg.pack()
Button(root, text="创建顶级窗口", command=create).pack()
mainloop()
本帖最后由 Twilight6 于 2020-6-29 10:35 编辑
这样即可:
- from tkinter import *
- root = Tk()
- def create():
- if list_:
- b = list_.pop()
- b.destroy()
- top = Toplevel()
- top.title("FishC Demo")
- list_.append(top)
- msg = Message(top, text="I love FishC.com!")
- msg.pack()
- list_ = []
- button = Button(root, text='创建顶级窗口', command=create)
- button.pack()
- mainloop()
复制代码
|
|