我有一些代码可以在用户按下按钮时创建一个顶级窗口。
但是,我想将顶级窗口的数量限制为一个,因此用户无法向按钮发送垃圾邮件并打开五十个窗口。
import tkinter as tk
class app():
def __init__(self,master):
self.master = master
master.configure(background = '#002e3d')
master.title('Test!')
master.geometry = master.geometry('660x550+200+200')
master.resizable(width = False,height = False)
self.button = tk.Button(master,text = 'Test'command = self.searchmenu)
self.button.pack()
def searchmenu(self):
Demo()
class Demo():
def __init__(self):
self.top = tk.Toplevel()
self.top.title('Search!')
def main():
root = tk.Tk()
window = app(root)
root.mainloop()