Set up menu and add action to it : Menu « GUI Tk « Python

Python
1. 2D
2. Application
3. Buildin Function
4. Class
5. Data Structure
6. Data Type
7. Database
8. Development
9. Dictionary
10. Event
11. Exception
12. File
13. Function
14. GUI Pmw
15. GUI Tk
16. Language Basics
17. List
18. Math
19. Network
20. String
21. System
22. Thread
23. Tuple
24. Utility
25. XML
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Python » GUI Tk » MenuScreenshots 
Set up menu and add action to it

from Tkinter import *

class AllTkinterWidgets:
    def __init__(self, master):
        frame = Frame(master, width=500, height=400, bd=1)
        frame.pack()

  self.mbar = Frame(frame, relief = 'raised', bd=2)
  self.mbar.pack(fill = X)

  self.filebutton = Menubutton(self.mbar, text = 'File')
  self.filebutton.pack(side = LEFT)

  self.filemenu = Menu(self.filebutton, tearoff=0)
  self.filebutton['menu'] = self.filemenu

  self.filemenu.add('command', label = 'Exit', command = self.quit)

  self.objectbutton = Menubutton(self.mbar, text = 'Object', )
  self.objectbutton.pack(side = LEFT)

  self.objectmenu = Menu(self.objectbutton, tearoff=0)
  self.objectbutton['menu'] = self.objectmenu

  self.objectmenu.add('command', label = 'object', command = self.stub)

    self.editbutton = Menubutton(self.mbar, text = 'Edit', )
  self.editbutton.pack(side = LEFT)

  self.editmenu = Menu(self.editbutton, tearoff=0)
  self.editbutton['menu'] = self.editmenu

  self.editmenu.add('command', label = 'edit', command = self.stub)

  self.viewbutton = Menubutton(self.mbar, text = 'View', )
  self.viewbutton.pack(side = LEFT)

  self.viewmenu = Menu(self.viewbutton, tearoff=0)
  self.viewbutton['menu'] = self.viewmenu

  self.viewmenu.add('command', label = 'view', command = self.stub)

  self.toolsbutton = Menubutton(self.mbar, text = 'Tools', )
  self.toolsbutton.pack(side = LEFT)

  self.toolsmenu = Menu(self.toolsbutton, tearoff=0)
  self.toolsbutton['menu'] = self.toolsmenu

  self.toolsmenu.add('command', label = 'tools', command = self.stub)

  self.helpbutton = Menubutton(self.mbar, text = 'Help', )
  self.helpbutton.pack(side = RIGHT)

  self.helpmenu = Menu(self.helpbutton, tearoff=0)
  self.helpbutton['menu'] = self.helpmenu

  self.helpmenu.add('command', label = 'help', command = self.stub)

    def quit(self):
        root.destroy()

    def stub(self):
        pass
    
root = Tk()
all = AllTkinterWidgets(root)
root.title('Tkinter Widgets')
root.mainloop()

           
       
Related examples in the same category
1. A big menu bar
2. Disable a menu itemDisable a menu item
3. Set menu item font
4. Menu item mouse on (active) foreground colorMenu item mouse on (active) foreground color
5. Underline for menu item textUnderline for menu item text
6. Menu separatorMenu separator
7. Cascade MenuCascade Menu
8. Disable a menuDisable a menu
9. Creating a small menuCreating a small menu
10. Menu separator 2 and menu action
11. Menu actionMenu action
12. Add menu to a windowAdd menu to a window
13. A Simple Form with Menu
14. Three Menu inside a formThree Menu inside a form
15. Framework for a single document interfaceFramework for a single document interface
16. 3 popup windows with menus3 popup windows with menus
17. Menu/tool bars packed before middleMenu/tool bars packed before middle
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.