home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / pyos2bin.zip / Demo / tkinter / matt / menu-simple.py < prev    next >
Text File  |  1996-08-21  |  3KB  |  119 lines

  1. from Tkinter import *
  2.  
  3. # some vocabulary to keep from getting confused. This terminology 
  4. # is something I cooked up for this file, but follows the man pages 
  5. # pretty closely
  6. #       This is a MENUBUTTON
  7. #       V
  8. # +-------------+
  9. # |             |
  10. # +------------++------------++------------+
  11. # |            ||            ||            |
  12. # |  File      ||  Edit      || Options    |   <-------- the MENUBAR
  13. # |            ||            ||            |
  14. # +------------++------------++------------+
  15. # | New...         |
  16. # | Open...        |
  17. # | Print          |
  18. # |                |  <------ This is a MENU. The lines of text in the menu are
  19. # |                |                          MENU ENTRIES
  20. # |                +---------------+
  21. # | Open Files >   | file1         |               
  22. # |                | file2         |
  23. # |                | another file  | <------ this cascading part is also a MENU
  24. # +----------------|               |
  25. #                  |               |
  26. #                  |               |
  27. #                  |               |
  28. #                  +---------------+
  29.  
  30.  
  31.  
  32. def new_file():
  33.     print "opening new file"
  34.  
  35.  
  36. def open_file():
  37.     print "opening OLD file"
  38.  
  39.  
  40. def makeFileMenu():
  41.     # make menu button : "File"
  42.     File_button = Menubutton(mBar, text='File', underline=0)
  43.     File_button.pack(side=LEFT, padx="1m")
  44.     File_button.menu = Menu(File_button)
  45.     
  46.     # add an item. The first param is a menu entry type, 
  47.     # must be one of: "cascade", "checkbutton", "command", "radiobutton", "seperator"
  48.     # see menu-demo-2.py for examples of use
  49.     File_button.menu.add_command(label='New...', underline=0, 
  50.                  command=new_file)
  51.     
  52.     
  53.     File_button.menu.add_command(label='Open...', underline=0, 
  54.                  command=open_file)
  55.     
  56.     File_button.menu.add_command(label='Quit', underline=0, 
  57.                  command='exit')
  58.  
  59.     # set up a pointer from the file menubutton back to the file menu
  60.     File_button['menu'] = File_button.menu
  61.  
  62.     return File_button
  63.  
  64.  
  65.  
  66. def makeEditMenu():
  67.     Edit_button = Menubutton(mBar, text='Edit', underline=0)
  68.     Edit_button.pack(side=LEFT, padx="1m")
  69.     Edit_button.menu = Menu(Edit_button)
  70.  
  71.     # just to be cute, let's disable the undo option:
  72.     Edit_button.menu.add('command', label="Undo")
  73.     # Since the tear-off bar is the 0th entry,
  74.     # undo is the 1st entry...
  75.     Edit_button.menu.entryconfig(1, state=DISABLED)
  76.  
  77.     # and these are just for show. No "command" callbacks attached.
  78.     Edit_button.menu.add_command(label="Cut")
  79.     Edit_button.menu.add_command(label="Copy")
  80.     Edit_button.menu.add_command(label="Paste")
  81.  
  82.     # set up a pointer from the file menubutton back to the file menu
  83.     Edit_button['menu'] = Edit_button.menu
  84.  
  85.     return Edit_button
  86.  
  87.  
  88. #################################################
  89.  
  90. #### Main starts here ...
  91. root = Tk()
  92.  
  93.  
  94. # make a menu bar
  95. mBar = Frame(root, relief=RAISED, borderwidth=2)
  96. mBar.pack(fill=X)
  97.  
  98. File_button = makeFileMenu()
  99. Edit_button = makeEditMenu()
  100.  
  101. # finally, install the buttons in the menu bar. 
  102. # This allows for scanning from one menubutton to the next.
  103. mBar.tk_menuBar(File_button, Edit_button)
  104.  
  105. root.title('menu demo')
  106. root.iconname('packer')
  107.  
  108. root.mainloop()
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.