Sorry Haze; I mistook "not exactly high priority" to mean "not worth investing in."
This line
root.input_text = Text(root, height = 10, width = 25).grid(row = 1, column = 1, sticky = N+S+E+W)
does the following:
* creates a new Text widget
* calls its .grid() method, which returns None
* then assigns it to root.input_text
So no matter what, root.input_text == None, NOT a Text widget.
Then later, when you call disable(), Surprise! 'None' doesn't have any methods.
BTW, in debugging things like this, I *always* print values of variables just to make sure that they are what I think they are...
What you really want is this:
root.input_text = Text(root, height = 10, width = 25)
root.input_text.grid(row = 1, column = 1, sticky = N+S+E+W)
Now with regard to the second problem,
def disable(widget):
widget["state"] = DISABLED
root.button2 = Button(root, text="Disable the Radiobutton", command=disable(root.button))
You can probably predict why the root.button is disabled from the beginning -- when you create root.button2, you *call* disable(root.button)!
So in your code, the act of creating root.button2 causes root.button to be disabled. Definitely not what you wanted.
I would solve your problem by using classes. What you want, if I read correctly, is for a bunch of buttons to have their own special "targets" that they can disable. Yes?
So what you really want is a type of Button() with a disable function attached to it. That calls for a new class that inherits from Button:
from Tkinter import *
class DisablerButton(Button):
def __init__(self, master, target, cnf={}, **kw):
Button.__init__(self, master, cnf, **kw)
self.target = target
self['command'] = self.disable
def disable(self):
self.target["state"] = DISABLED
mainw = Tk()
mainw.b1 = Button(mainw, height=5,width=10, text="My Button")
mainw.b2 = DisablerButton(mainw, mainw.b1, height=5, width=10, text="Press Me!")
mainw.b3 = DisablerButton(mainw, mainw.b2, height=5,width=10, text="Me Too!")
mainw.b1.grid()
mainw.b2.grid()
mainw.b3.grid()
mainw.mainloop()
There's a couple things that need explaining. First, the __init__ method for Button can take a lot of arguments. The **kw refers to all of the configuration arguments like width= and height=. cnf is a less commonly used way to package those configuration options into a dictionary. Rather than spell all those arguments out, I just package them up and pass them upstairs to Button.__init__.
Second, notice that this way of doing things allows you to specify a different target for each individual DisablerButton widget. I think this is what you wanted.
Can you see why a class is required to do this?
Jeff