There is a script that by clicking on the button creates a new window. How can I make it so that a new window is not created by pressing a button if this window is already open? Here is the code:

#-*- coding: utf-8 -*- from tkinter import * root = Tk() root.geometry('700x700') root.title('Root') def new_window(event): window = Toplevel(root) lab = Label(root, text='Press here') but = Button(root, text='Ok') but.bind('<Button->', new_window) lab.pack() but.pack() root.mainloop() 

1 answer 1

You can withdraw() / deiconify() instead of creating / destroying a window.

  • And you can not have much more detail. I just had the same question - user268178
  • @KuzminAlexey methods minimize / maximize the window. Try root.withdraw() , and then root.deiconify() after some time. - jfs