[Pythonmac-SIG] Pmw.OptionMenu woes

James E. Scarborough JAMES.E.SCARBOROUGH@saic.com
Thu, 6 Mar 2003 14:34:10 -0500


Hi,

Here's a puzzle that has me stumped.

The following code segment (which works fine on our Linux box) shows  
that you can't open a dialog as a result of the command event on a  
Pmw.OptionMenu, and then change the value of the Pmw.OptionMenu that  
pops up in the resulting window.

I'm running MacOS X with Python 2.2.2, Pmw 1.1, and Tk 8.4.1.

Why this example?  I've developed a Python app on the Linux box and am  
trying to port it to the Mac.  With hardly any effort it seems to work  
- except for this detail - and the menu bar shows up across the top of  
the root window implemented as Pmw.OptionMenu items.  Several menu  
items open dialog boxes that use Pmw.OptionMenus.

I tried launching a new thread with thread.start_new_thread(...) and  
immediately got a spectacular crash - apparently start_new_thread isn't  
the right approach.

Did I miss something obvious?  Has my mostly-Java background led me  
astray?

Any hints on how I might get this example - or something very much like  
it - to work are much appreciated.

Many thanks,
Jim


import Pmw
from Tkinter import *

def execute(result):
     dialog.deactivate(result)
     print "Result=" + `result`

def _simpleDialogTest(*argv):
    globals()['dialog']=dialog=Pmw.Dialog(
        root.winfo_toplevel(), buttons=['Ok','Cancel'],
        defaultbutton='Ok', title='test', command=execute)
    hull=dialog.component('hull')
    menu=Pmw.OptionMenu(hull,items=['a','b','c','d'],initialitem='b')
    menu.pack(fill=BOTH,expand=1)
    dialog.activate()

root=Tk()
rootMenu=Pmw.OptionMenu(root,items=['greetings','salutations','hi'],comm 
and=_simpleDialogTest)
rootMenu.pack(fill=BOTH,expand=1)

root.mainloop()