The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

clnethery (1) [Avatar] Offline
#1
Hello everyone. I am fairly new to both Python and Tkinter and have 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. I have included code to illustrate the problem.

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.

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=1smilie
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=1smilie
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()

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