I'm writing an app that requires a 3-level optionMenu display. Basically
I'm showing the contents of a 3-dimensional matrix. You choose the first
level in the first optionMenu, the 2nd level in the next level, and the 3rd
level in the last optionMenu. Let's call them Continent,count ry,state.
continentList = ['N.America', 'S. America', 'Europe', 'Asia', Africa',
'Australia', 'Antarctica']
countryList = [['Canada', 'USA', 'Mexico'],['Argentina','Ch ile', ..],[other
continents' countries... ]]
stateList = [[['BC','Alberta', ...
'Newfoundland'],['California','O regon',...'Main e'],['Guadalajara',. ..]],[[other
continents' countries' states]]
When I open the window, all is well. I can display the following as default
selections:
[ N. America ]
[ Canada ]
[ B.C. ]
Making a selection of a continent, country or state invokes a _getSelection
method that displays the 3 choices. So far so good.
Also, if I change the continent selection, then I get a different default
country in the 2nd optionMenu. But, this is where is goes wrong. I can't
get the list of countries to be updated in the 2nd optionMenu, nor the list
of states to be updated in the state list. How would I do this?
I've tried to include some code at the end of the _getSelection method but
it isn't working. Does anyone has any similar code that they can share?
global continentItems, countryItems, stateItems
def _getSelection(s elf, choice):
print 'you have chosen %s %s %s' % \
(self.var1.get( ),
self.var2.get() ,
self.var3.get() )
# above code correctly prints the selected choices from all 3 levels
# next part of code tries to re-draw country list based on
# continent selection, but it doesn't work.
# next line successfully gets list index of chosen continent
i2 = indexContinents (self.var1.get( )
# first item in countryList is name of associated continent
self.var2.set(c ountryList[i2][0])
# next line correctly contains list of countries for selected continent
countryItems = countryList[i2]
# next line croaks: trying to change the 'items' option for optionMenu
# by directly addressing its 'items' parameter: no good
self.method2_me nu.config(items = countryItems)
stuck here! 1 2102
Here's a test app to demonstrate the concept, and the difficulty.
#file testselectstate .py
title = 'LeakWarn System Selection'
# Import Pmw from this directory tree.
import sys
sys.path[:0] = ['../../..']
import Tkinter
import Pmw, re
global continentList, countryList, stateList
continentList = ['N.America','C. America', 'S. America']
countryList = [['Canada','USA', 'Mexico'],
['Guatemala','Ni caragua','Panam a'],
['Venezuela','Co lombia','Ecuado r']]
stateList = [[['BC','Alberta', 'Saskatchewan', 'others'],
['California','O regon','Washing ton','others'],
['Michoacan','Oa xaca','Monterre y','others']],
[['Guatemala states'],['Nicaragua states'],['Panama states']],
[['Venezuela states'],['Colombia states'],['Ecuador states']]]
# default selection
continentItem = continentList[0]
countryItem = countryList[0][0]
stateItem = stateList[0][0][0]
class selectSystem:
def __init__(self, parent):
# Create and pack the OptionMenu megawidgets.
# The first one has a textvariable.
self.var1 = Tkinter.StringV ar()
self.var2 = Tkinter.StringV ar()
self.var3 = Tkinter.StringV ar()
self.var1.set(c ontinentItem) # N. America
self.var2.set(c ountryItem) # Canada
self.var3.set(s tateItem) # B.C.
self.method1_me nu = Pmw.OptionMenu( parent,
labelpos = 'w',
label_text = 'Select Continent:',
menubutton_text variable = self.var1,
items = continentList,
menubutton_widt h = 20,
menubutton_dire ction = 'flush',
command = self._getSelect ion
)
self.method1_me nu.pack(anchor = 'w', padx = 10, pady = 10)
self.method2_me nu = Pmw.OptionMenu (parent,
labelpos = 'w',
label_text = 'Select country:',
menubutton_text variable = self.var2,
items = countryList[0],
menubutton_widt h = 20,
menubutton_dire ction = 'flush',
command = self._getSelect ion
)
self.method2_me nu.pack(anchor = 'w', padx = 10, pady = 10)
self.method3_me nu = Pmw.OptionMenu (parent,
labelpos = 'w',
label_text = 'Select state:',
menubutton_text variable = self.var3,
items = stateList[0][0],
menubutton_widt h = 20,
menubutton_dire ction = 'flush' ,
command = self._getSelect ion
)
self.method3_me nu.pack(anchor = 'w', padx = 10, pady = 10)
menus = (self.method1_m enu, self.method2_me nu, self.method3_me nu)
Pmw.alignlabels (menus)
# Create the dialog.
self.dialog = Pmw.Dialog(pare nt,
buttons = ('OK', 'Apply', 'Cancel', 'Help'),
defaultbutton = 'OK',
title = 'Select State',
command = self.execute)
self.dialog.wit hdraw()
# Add some contents to the dialog.
w = Tkinter.Label(s elf.dialog.inte rior(),
text = 'Pmw Dialog\n(put your widgets here)',
background = 'black',
foreground = 'white',
pady = 20)
w.pack(expand = 1, fill = 'both', padx = 4, pady = 4)
def showAppModal(se lf):
self.dialog.act ivate(geometry = 'centerscreenal ways')
def execute(self, result):
print 'You clicked on', result
if result not in ('Apply', 'Help'):
self.dialog.dea ctivate(result)
def _getSelection(s elf, choice):
# Can use 'self.var.get() ' instead of 'getcurselectio n()'.
print 'You have chosen %s : %s : %s' % \
(self.var1.get( ),
self.var2.get() ,
self.var3.get() )
print choice # debug
i2 = indexContinent( self.var1.get() )
self.var2.set(c ountryList[i2][0])
countryItem = countryList[i2]
#print pipelineItems # debug
self.method2_me nu.config(items = countryList)
#s3 = systemElements. indexpipe(s2,te st2)
def __call__(self):
self.dialog.sho w()
def indexContinent( name):
found = 'false'
for i in range(len(conti nentList)):
check = continentList[i]
# print 'checking %s in %s' % (name, check) # debug
if re.search(name, check):
found = 'true'
break
print found
if (found=='true') :
#print 'index of %s is %s' % (name,i) # debug
return i
else:
return -1
def indexCountry(co ntinentindex, name):
found = 'false'
for i in range(len(count ryList[continentindex])):
check = countryList[continentindex][i]
# print 'checking %s in %s' % (name, check) # debug
if re.search(name, check):
found = 'true'
break
print found
if (found=='true') :
#print 'index of %s is %s' % (name,i) # debug
return i
else:
return -1
############### ############### ############### ############### ##########
# Create selectSystem in root window for testing.
if __name__ == '__main__':
root = Tkinter.Tk()
Pmw.initialise( root)
root.title(titl e)
OKButton = Tkinter.Button( root, text = 'OK', command = root.destroy)
OKButton.pack(s ide = 'bottom')
widget = selectSystem(ro ot)
root.mainloop() This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stewart Midwinter |
last post by:
I would like to link the contents of three OptionMenu lists. When I select an
item from the first list (call it continents), the contents of the 2nd list
(call it countries) would update. And in turn the contents of the 3rd list (call
it states would be updated by a change in the 2nd list. If anyone can share a
recipe or some ideas, I'd be grateful!
Here's some sample code that displays three OptionMenus, but doesn't update the
list...
|
by: Jeffrey Barish |
last post by:
Is there a way to fill the values in an OptionMenu dynamically? I need
something like the add_command method from Menu. Is there a better way
to implement a pull-down list?
--
Jeffrey Barish
|
by: Martin |
last post by:
I'd like to change the way the button that appears in an OptionMenu
instance, but have been umable to figure out how to do this. The
default constructor won't allow you to pass an 'image=" keyword.
The standard visual I am talking about is displayed as basically a
small rectangle drawn in relief inside a larger one. I'd like to
replace that with something like a downward pointing arrowhead.
I tried creating a OptionMenu-like class of...
|
by: mariox19 |
last post by:
Hello,
The Tkinter OptionMenu widget has me a bit confused. I have set up an
OptionMenu to expand along the X axis as the window expands. What I
find though is that the width of the submenu displaying the list of
items in the menu does not expand.
This is the object I'm talking about:
<code>
|
by: erikober |
last post by:
I'm creating a OptionMenu button for a gui and I'm having a problem
where the drop down list is so long that most of the options are off
screen. The correct behavior would be that another drop down menu list
would be created next to it with the continued options. Here is the
small code snippet that I have now:
myOptionList = .......
OMcreate = "OptionMenu(frame, myVar, \"%s\",
command=myOMCB)"%(myOptionList)
| |
by: Nathan Bloomfield |
last post by:
Does anyone know if there is any documentation which relates to Access2k + ?
or can anyone help adjust the code?
I am having trouble converting the DAO references.
TITLE :INF: How to Create a Dynamic Crosstab Report
PRODUCT :Microsoft Access
PROD/VER:1.00 1.10
OPER/SYS:WINDOWS
|
by: bu |
last post by:
I have a form with a handful of comments fields. I am trying to code the
form in such a way that when the user clicks on the field, a dialog box will
open up displaying the full contents of the field. I want to reuse the same
window for each field ( seems sensless to code a screen n times for n fields
when the only thing that is really changing is the source data ), but am
having all sorts of issues. I have tried dynamically setting the...
|
by: |
last post by:
Hi,
I am just progamming using asp.net, and I want create a usercontrol to
display some dynamic(from database) contents.
Is this possible? Is there any sample code ?
Thanks in advance!
Ray
|
by: sandy |
last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory',
within my class Directory (Can you already smell disaster?)
Each Directory can have subdirectories so I thought to put these in an
array. The application compiles but aborts without giving me any useful
information.
What I suspect is happening is infinite recursion. Each Directory
object creates an array of Subdirectories each of which has an array of...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |