diff options
Diffstat (limited to 'Demo/tkinter/matt/menu-all-types-of-entries.py')
-rw-r--r-- | Demo/tkinter/matt/menu-all-types-of-entries.py | 104 |
1 files changed, 49 insertions, 55 deletions
diff --git a/Demo/tkinter/matt/menu-all-types-of-entries.py b/Demo/tkinter/matt/menu-all-types-of-entries.py index 1ac51c81ff..f4afe4a8b6 100644 --- a/Demo/tkinter/matt/menu-all-types-of-entries.py +++ b/Demo/tkinter/matt/menu-all-types-of-entries.py @@ -1,16 +1,16 @@ from Tkinter import * -# some vocabulary to keep from getting confused. This terminology -# is something I cooked up for this file, but follows the man pages +# some vocabulary to keep from getting confused. This terminology +# is something I cooked up for this file, but follows the man pages # pretty closely -# -# -# +# +# +# # This is a MENUBUTTON # V # +-------------+ # | | -# +# # +------------++------------++------------+ # | || || | # | File || Edit || Options | <-------- the MENUBAR @@ -22,7 +22,7 @@ from Tkinter import * # | | <-------- This is a MENU. The lines of text in the menu are # | | MENU ENTRIES # | +---------------+ -# | Open Files > | file1 | +# | Open Files > | file1 | # | | file2 | # | | another file | <------ this cascading part is also a MENU # +----------------| | @@ -53,11 +53,11 @@ def print_anchovies(): print "anchovies?", anchovies def makeCommandMenu(): - # make menu button - Command_button = Menubutton(mBar, text='Simple Button Commands', - underline=0) + # make menu button + Command_button = Menubutton(mBar, text='Simple Button Commands', + underline=0) Command_button.pack(side=LEFT, padx="2m") - + # make the pulldown part of the File menu. The parameter passed is the master. # we attach it to the button as a python attribute called "menu" by convention. # hopefully this isn't too confusing... @@ -68,28 +68,28 @@ def makeCommandMenu(): # undo is the 0th entry... Command_button.menu.entryconfig(0, state=DISABLED) - Command_button.menu.add_command(label='New...', underline=0, - command=new_file) - Command_button.menu.add_command(label='Open...', underline=0, - command=open_file) + Command_button.menu.add_command(label='New...', underline=0, + command=new_file) + Command_button.menu.add_command(label='Open...', underline=0, + command=open_file) Command_button.menu.add_command(label='Different Font', underline=0, - font='-*-helvetica-*-r-*-*-*-180-*-*-*-*-*-*', - command=print_something) - + font='-*-helvetica-*-r-*-*-*-180-*-*-*-*-*-*', + command=print_something) + # we can make bitmaps be menu entries too. File format is X11 bitmap. # if you use XV, save it under X11 bitmap format. duh-uh.,.. Command_button.menu.add_command( - bitmap="info") - #bitmap='@/home/mjc4y/dilbert/project.status.is.doomed.last.panel.bm') - + bitmap="info") + #bitmap='@/home/mjc4y/dilbert/project.status.is.doomed.last.panel.bm') + # this is just a line Command_button.menu.add('separator') # change the color - Command_button.menu.add_command(label='Quit', underline=0, - background='red', - activebackground='green', - command=Command_button.quit) + Command_button.menu.add_command(label='Quit', underline=0, + background='red', + activebackground='green', + command=Command_button.quit) # set up a pointer from the file menubutton back to the file menu Command_button['menu'] = Command_button.menu @@ -99,10 +99,10 @@ def makeCommandMenu(): def makeCascadeMenu(): - # make menu button + # make menu button Cascade_button = Menubutton(mBar, text='Cascading Menus', underline=0) Cascade_button.pack(side=LEFT, padx="2m") - + # the primary pulldown Cascade_button.menu = Menu(Cascade_button) @@ -125,12 +125,12 @@ def makeCascadeMenu(): Cascade_button.menu.choices.add_command(label='Rocky Road') Cascade_button.menu.choices.add_command(label='BubbleGum') Cascade_button.menu.choices.add_cascade( - label='Wierd Flavors', - menu=Cascade_button.menu.choices.wierdones) + label='Wierd Flavors', + menu=Cascade_button.menu.choices.wierdones) # and finally, the definition for the top level - Cascade_button.menu.add_cascade(label='more choices', - menu=Cascade_button.menu.choices) + Cascade_button.menu.add_cascade(label='more choices', + menu=Cascade_button.menu.choices) Cascade_button['menu'] = Cascade_button.menu @@ -138,39 +138,39 @@ def makeCascadeMenu(): def makeCheckbuttonMenu(): global fred - # make menu button - Checkbutton_button = Menubutton(mBar, text='Checkbutton Menus', - underline=0) + # make menu button + Checkbutton_button = Menubutton(mBar, text='Checkbutton Menus', + underline=0) Checkbutton_button.pack(side=LEFT, padx='2m') - + # the primary pulldown Checkbutton_button.menu = Menu(Checkbutton_button) # and all the check buttons. Note that the "variable" "onvalue" and "offvalue" options - # are not supported correctly at present. You have to do all your application + # are not supported correctly at present. You have to do all your application # work through the calback. Checkbutton_button.menu.add_checkbutton(label='Pepperoni') Checkbutton_button.menu.add_checkbutton(label='Sausage') Checkbutton_button.menu.add_checkbutton(label='Extra Cheese') # so here's a callback - Checkbutton_button.menu.add_checkbutton(label='Anchovy', - command=print_anchovies) + Checkbutton_button.menu.add_checkbutton(label='Anchovy', + command=print_anchovies) - # and start with anchovies selected to be on. Do this by + # and start with anchovies selected to be on. Do this by # calling invoke on this menu option. To refer to the "anchovy" menu # entry we need to know it's index. To do this, we use the index method - # which takes arguments of several forms: + # which takes arguments of several forms: # # argument what it does # ----------------------------------- - # a number -- this is useless. + # a number -- this is useless. # "last" -- last option in the menu # "none" -- used with the activate command. see the man page on menus # "active" -- the currently active menu option. A menu option is made active # with the 'activate' method # "@number" -- where 'number' is an integer and is treated like a y coordinate in pixels - # string pattern -- this is the option used below, and attempts to match "labels" using the + # string pattern -- this is the option used below, and attempts to match "labels" using the # rules of Tcl_StringMatch Checkbutton_button.menu.invoke(Checkbutton_button.menu.index('Anchovy')) @@ -181,16 +181,16 @@ def makeCheckbuttonMenu(): def makeRadiobuttonMenu(): - # make menu button - Radiobutton_button = Menubutton(mBar, text='Radiobutton Menus', - underline=0) + # make menu button + Radiobutton_button = Menubutton(mBar, text='Radiobutton Menus', + underline=0) Radiobutton_button.pack(side=LEFT, padx='2m') - + # the primary pulldown Radiobutton_button.menu = Menu(Radiobutton_button) # and all the Radio buttons. Note that the "variable" "onvalue" and "offvalue" options - # are not supported correctly at present. You have to do all your application + # are not supported correctly at present. You have to do all your application # work through the calback. Radiobutton_button.menu.add_radiobutton(label='Republican') Radiobutton_button.menu.add_radiobutton(label='Democrat') @@ -209,7 +209,7 @@ def makeRadiobuttonMenu(): return Radiobutton_button -def makeDisabledMenu(): +def makeDisabledMenu(): Dummy_button = Menubutton(mBar, text='Dead Menu', underline=0) Dummy_button.pack(side=LEFT, padx='2m') @@ -233,7 +233,7 @@ Checkbutton_button = makeCheckbuttonMenu() Radiobutton_button = makeRadiobuttonMenu() NoMenu = makeDisabledMenu() -# finally, install the buttons in the menu bar. +# finally, install the buttons in the menu bar. # This allows for scanning from one menubutton to the next. mBar.tk_menuBar(Command_button, Cascade_button, Checkbutton_button, Radiobutton_button, NoMenu) @@ -242,9 +242,3 @@ root.title('menu demo') root.iconname('menu demo') root.mainloop() - - - - - - |