Reputation: 65
For my bigger application I have a Tk Frame that spawns upon right clicking. I want all the focus of the window to be directed towards this frame (If the user clicks on a button on the parent then nothing happens) and then when the frame is destroyed I want it to go back to normal. I created a minimal example to demonstrate what I have tried to do and it is not working.
I simply want the Root button (Say hi) to be disabled after clicking Disable Outer.
import tkinter as tk
class app(tk.Frame):
def __init__(self, parent,*args,**kwargs):
tk.Frame.__init__(self, parent,*args,**kwargs)
self.parent=parent
toggler = tk.Button(self,text='DISABLE OUTER',command=self.toggleMain)
toggler.pack(padx=20,pady=20)
def toggleMain(self):
status= self.parent.grab_status()
if not status:
print('Outer Is Disabled (Hi Should not work)')
self.parent.grab_set_global()
else:
print('Outer is Enabled (Hi should work)')
self.parent.grab_release()
root = tk.Tk()
app = app(root,bg='red')
app.pack()
def SayHi():
print('Hi There')
f=tk.Button(root,text='Say Hi',command=SayHi)
f.pack()
root.mainloop()
Upvotes: 0
Views: 1066
Reputation: 1227
I'm not sure what it is you are trying to do, but if all you want to do is disable the button that says ""Say Hi" is to disable it.
import tkinter as tk
class app(tk.Frame):
def __init__(self, parent,*args,**kwargs):
tk.Frame.__init__(self, parent,*args,**kwargs)
self.parent=parent
toggler = tk.Button(self,text='DISABLE OUTER',command=self.toggleMain)
toggler.pack(padx=20,pady=20)
def toggleMain(self):
status= self.parent.grab_status()
if not status:
print('Outer Is Disabled (Hi Should not work)')
self.grab_set()
else:
print('Outer is Enabled (Hi should work)')
self.grab_release()
root = tk.Tk()
app = app(root,bg='red')
app.pack()
def SayHi():
print('Hi There')
f=tk.Button(root,text='Say Hi',command=SayHi)
f.pack()
root.mainloop(
Upvotes: 1