[Tkinter-discuss] Graying out and disabling widgets

Chris Nethery clnethery at juno.com
Thu Apr 29 23:55:11 EDT 2004


Hello everyone.  I have once again come up with an issue I cannot seem to resolve, although I would have thought it simple.

I am trying to "gray out" and disable widgets when they lose focus.  To that end, the code works.  The problem is...it takes two mouse clicks on the widget to facilitate the method.  To illustrate this, type anything in the entry field and hit enter...so far, so good...now select an item from the combobox...that enables the combobox but does not populate the combobox's entry with the item--the item must be selected a second time in order for this to happen.  I have included the code for your perusal...

Any ideas? 


Thanking you in advance,

Chris Nethery

############################################
from Tkinter import *
import Pmw

root = Tk()
root.title('Graying out and disabling')
#root.wm_geometry("1015x705")
Pmw.initialise(root)



class GrayOutAndDisableMethod:
 
    def __init__(self, root):

        Frame1 = Frame(root, borderwidth=2, width=1015, height=705)
        Frame1.pack(fill='both', expand=1, padx=5, pady=5)
        Frame1.place(relx=0.01, rely=0.01, anchor=NW)

        Frame2 = Frame(Frame1, borderwidth=2, width=300, height=18)
        self.ConstantEntryField = Pmw.EntryField(Frame2, labelpos=W, labelmargin=30, label_text='1) Input stuff:', command = self.constantValue)
        self.ConstantEntryField.pack(fill=X, expand=1, padx=5, pady=5)
        Frame2.pack(fill='both', expand=1, padx=5, pady=5)
        Frame2.place(relx=0.01, rely=0.08, anchor=NW)

        Frame3 = Frame(Frame1, borderwidth=2, width=300, height=18)
        MapComboItems = ('', 'item1', 'item2', 'item3', 'item4', 'item5', 'item6', 'item7', 'item8', 'item9', 'item10')
        self.MapComboBox = Pmw.ComboBox(Frame3, history=0, listheight=150, label_text='2) Select stuff:', labelmargin=24, labelpos='w', selectioncommand=self.mapSelection, scrolledlist_items=MapComboItems)
        self.MapComboBox.pack(side='right', anchor='w', fill='x', expand=1, padx=5, pady=5)
        Frame3.pack(fill='both', expand=1, padx=5, pady=5)
        Frame3.place(relx=0.01, rely=0.14, anchor=NW)

    def constantValue(self):
        if self.ConstantEntryField.get() == '' or None:
            self.ConstantEntryField.component('entry').config(state='normal')
            self.MapComboBox.component('entry').config(state='normal')
            self.MapComboBox.component('listbox').config(state='normal')
        else:
            self.ConstantEntryField.component('entry').config(state='normal')
            self.MapComboBox.component('entry').config(state='disabled')
            self.MapComboBox.component('listbox').config(state='disabled')


    def mapSelection(self, event):
        if self.MapComboBox.get() != '' or None:
            self.MapComboBox.component('entry').config(state='normal')
            self.MapComboBox.component('listbox').config(state='normal')
            self.ConstantEntryField.clear()
            self.ConstantEntryField.component('entry').config(state='disabled')
        else:
            self.MapComboBox.component('entry').config(state='normal')
            self.MapComboBox.component('listbox').config(state='normal')
            self.ConstantEntryField.component('entry').config(state='normal')
 
nbn = GrayOutAndDisableMethod(root)

root.mainloop()

###############################################



More information about the Tkinter-discuss mailing list