TKinter question - A combo box / menu question
Paul Sage
psage at ncaustin.com
Tue Mar 26 14:07:18 EST 2002
I am trying to build a very simple menu portion of a program. I have
the main frame created and the menu box is a widget in that frame. The
menu is a straight pull down menu. However, in the "LOAD" part of the
menu where I would like to create a pop-up combo box when load is
selected from the menu. I have created both working widgets, but every
time I execute the program, it pops up the ComboDialogBox. I want this
box to be a part of an event, not actually being built. Can anyone help
with this?
class TopMenuBar:
def __init__(self, parent):
menu_Bar = Frame(parent, relief=GROOVE, borderwidth =1)
menu_Bar.pack(fill=X)
FileBtn = self.player_Load_Menu(menu_Bar)
ConfigureBtn = self.player_Configure_Menu(menu_Bar)
def player_Load_Menu(self, menu_Bar):
#Create the first top menu item
CmdBtn = Menubutton(menu_Bar, text='Character Selection',
underline=0)
CmdBtn.pack(side=LEFT)
CmdBtn.menu = Menu(CmdBtn, tearoff=0)
#Begin creating the items in the first top menu
CmdBtn.menu.add_command(label="Load Form",
command=self.open_file(menu_Bar))
CmdBtn.menu.add_command(label="Save Form", command=self.save_file)
CmdBtn.menu.add_command(label="New Form", command=self.new_file)
CmdBtn.menu.add('separator')
CmdBtn.menu.add_command(label="Quit", command=self.quit_file)
CmdBtn['menu'] = CmdBtn.menu
return(CmdBtn)
def player_Configure_Menu(self, menu_Bar):
#Create the second top menu item
CmdBtn = Menubutton(menu_Bar, text='Configure Form', underline=0)
CmdBtn.pack(side=LEFT)
CmdBtn.menu = Menu(CmdBtn, tearoff=0)
#Begin creating the items in the second top menu
CmdBtn.menu.add_command(label="Add level", command=self.add_level)
CmdBtn.menu.add_command(label="Subtract level",
command=self.subtract_level)
CmdBtn['menu'] = CmdBtn.menu
return(CmdBtn)
def open_file(self, parent):
#Need the listofcharacters to be a tuple sequence.
from char_edit_combo_load import *
forms = []
listOfCharacters = tuple(getFiles(forms))
dialog = Pmw.ComboBoxDialog(parent, title = "Character Load",
buttons = ('OK', 'Cancel'),
defaultbutton = 'OK',
combobox_labelpos=N, label_text="Please
select a character",
scrolledlist_items=listOfCharacters,
listbox_width=22)
dialog.withdraw()
result=dialog.activate()
# The function has now opened seen the selection, time to open the
file.
if result == 'OK':
return(readObjectFromFile(dialog.get()))
else:
return(None)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20020326/ea8e09dc/attachment.html>
More information about the Python-list
mailing list