enable/disable widgets with checkbox(TKinter)

mark mark at diversiform.com
Tue Nov 4 22:23:56 CET 2003


I'm not aware of a disable method for Entry, but you can set its 'state'
option to DISABLED or NORMAL for inactive or active, respectively.

In case you hadn't gotten there yet, you can throw in a little something
to check the status of the checkbutton to determine if it needs to
enable or disable the entry fields.

def FlipState(self):
	self.test = self.CheckMode.get()
	if self.test == 1:	#checked
		self.input_box['state'] = DISABLED
	elif self.test == 0:	#unchecked
		self.input_box['state'] = NORMAL

I haven't tested this code completely, and it doesn't check to see if,
for some reason, the input box isn't in the correct state for the
checkbutton status, but it should point you in the right direction.

- Mark


-----Original Message-----
From: python-list-bounces+mark=diversiform.com at python.org
[mailto:python-list-bounces+mark=diversiform.com at python.org] On Behalf
Of jwsacksteder at ramprecision.com
Sent: Tuesday, November 04, 2003 12:40 PM
To: python-list at python.org
Subject: enable/disable widgets with checkbox(TKinter)

I want to have a check box that can optionally disable a text input
field in
the same dialog. I am asking the user to input the start and end of a
range
and there needs to be a check box to select all items. When the checkbox
changes state, I want to ghost-out the input fields.

A rough approximation of the situation follows.

class mystuff(Frame):
    def __init__(self,parent=None):
        Frame.__init__(self,parent)
        self.CheckMode = IntVar()
        
        self.mode_label = Label(self, text='All Line Items?',
borderwidth='5')
        self.mode_box = Checkbutton(self,
width='1',variable=self.CheckMode,command=self.FlipState)
        self.input_label = Label(self, text='Input Name',
borderwidth='5')
        self.input_box = Entry(self, width='3')

        self.pack()

    def FlipState(self):
        #This does not work!
        self.input_box.disable()
        print "variable is", self.LineItemMode.get() 

-- 
http://mail.python.org/mailman/listinfo/python-list







More information about the Python-list mailing list