Python tkinter, how to disable background buttons from being clicked Python tkinter, how to disable background buttons from being clicked tkinter tkinter

Python tkinter, how to disable background buttons from being clicked


You will want to call grab_set on the TopLevel window so that all keyboard and mouse events are sent to that.

def exportEFS(self):  self.exportGUI = Toplevel()  Button(self.exportGUI, text='Backup', command=self.backup).pack(padx=100,pady=5)  Button(self.exportGUI, text='Restore', command=self.restore).pack(padx=100,pady=5)def backup(self):  self.backupWindow = Toplevel()  self.backupWindow.grab_set()  message = "Enter a name for your Backup."  Label(self.backupWindow, text=message).pack()  self.entry = Entry(self.backupWindow,text="enter your choice")  self.entry.pack(side=TOP,padx=10,pady=12)  self.button = Button(self.backupWindow, text="Backup",command=self.backupCallBack)  self.button.pack(side=BOTTOM,padx=10,pady=10)


What you can do is set the state to disabled. As so:

self.button.config(state="disabled")

And to enable it, you just use:

self.button.config(state="normal")

However, you must assign your buttons to variables first, like this:

self.backup=Button(self.exportGUI, text='Backup', command=self.backup)self.backup.pack(padx=100,pady=5)self.restore=Button(self.exportGUI, text='Restore', command=self.restore)self.restore.pack(padx=100,pady=5)

so you would disable these using:

self.backup.config(state="disabled")self.restore.config(state="disabled")

and re-enable using:

self.backup.config(state="normal")self.restore.config(state="normal")

Please note however, that while the button is disabled, nothing can be changed to that button, both through the code, or through the user using it. So that means if you wanted to change the text of that button, you would have to change the state of the button to "normal" before changing it (if it already isn't in that state, which by default, all widgets are in that state when first created).

Cheers :)