There are a couple different ways that first come to mind.
One way would be just to disable interaction with the entire window, this would be done by using the .grab_set()
method on your newly created window.
def create_window():
window = tk.Toplevel(root)
window.grab_set()
This method means the created window is now focused on, when the focused window is destroyed you will then again be able to interact with other windows.
Another way would be to have your function create_window()
take the button as an input, then use the .configure(state="disabled")
on the button
def create_window(button):
window = tk.Toplevel(root)
button.configure(state="disabled")
root = tk.Tk()
b = tk.Button(root, text="Create new window", command=lambda: create_window(b))
b.pack()
Please note that since your function needs an input now, you need to use command= lambda:create_window(b)
so then the create_window()
isn't run when the button is created.
However now you would have to write another function that will change the buttons state back to .configure(state="normal")
when the new window is destroyed. e.g.
def create_window(button):
window = tk.Toplevel(root)
def on_close():
button.configure(state="normal")
window.destroy()
button.configure(state="disabled")
window.protocol("WM_DELETE_WINDOW", on_close)