| | |
How to create menu in python?
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 12
Reputation:
Solved Threads: 0
Can someone guide me how to make menu in python please?
http://www.daniweb.com/forums/post69...tml#post693793
This is a previous post of what sort of menu i need.
Can someone just give me a start please.
Cheers
http://www.daniweb.com/forums/post69...tml#post693793
This is a previous post of what sort of menu i need.
Can someone just give me a start please.
Cheers
It really depends. Are you using wxPython Tkinter or some other kind of GUI becuase they all differ.
I can give you an example in wxPython
Hope that helps!
I can give you an example in wxPython
python Syntax (Toggle Plain Text)
import wx class MainFrame(wx.Frame): def __init__(self): wx.Frame.__init__(self,None) self.menubar = wx.MenuBar() self.file = wx.Menu() self.file.Append(wx.ID_ANY,'&Test') self.menubar.Append(self.file,'File') self.SetMenuBar(self.menubar) self.Show() app = wx.App(False) frame = MainFrame() app.MainLoop()
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
python Syntax (Toggle Plain Text)
Start with this! import wx class TextEditor(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(350, 600)) # self/Text editor is now a Window with all attribute of a frame # create status bar self.CreateStatusBar() # set default status bar string self.SetStatusText("For help press F1") # define sizers vbox = wx.BoxSizer(wx.VERTICAL) hbox = wx.BoxSizer(wx.HORIZONTAL) #Add menu #define menubar and menu menubar = wx.MenuBar() # attach menubar to the frame self.SetMenuBar(menubar) #define menus filemenu = wx.Menu() # Append items filemenu.Append(-1, "&New", "New Blank file") #----------------------------------------------- # Append a separator filemenu.AppendSeparator() #Print menu filemenu.Append(-1, "&Print", "Print file") #------------------------------------------------------- #Append print menu to menubar menubar.Append(filemenu, "&File") #------------------------------------ #center the window self.Center() #show the window(without this the windows will not show up) self.Show(True) #our main application app = wx.App(False) TextEditor(None, -1, "Text Editor") app.MainLoop()
Last edited by evstevemd; Sep 27th, 2008 at 6:48 am. Reason: code blocking! Some code tags arranging
what do you need to add?
Make it idiot proof and someone will make a better idiot.
Check out my Site | and join us on IRC | Python Specific IRC
Check out my Site | and join us on IRC | Python Specific IRC
•
•
Join Date: Sep 2008
Posts: 12
Reputation:
Solved Threads: 0
I need to add
"Your program should display a menu which will allow the user to choose whether he wants to (1)
coefficients (2) check whether the linear system can be solved using iteration (3) calculate and display the
required results using Gauss-Seidel (4) calculate and display the required results using Gauss-Jacobi"
I need from the above question 4 menu that the user can click from.
Also i would be grateful if someone could tell me how i modify the codes for any particular menu(i worked in Visual Basic 6.0 where interfaces are much easier than python)
Thnx again.
"Your program should display a menu which will allow the user to choose whether he wants to (1)
coefficients (2) check whether the linear system can be solved using iteration (3) calculate and display the
required results using Gauss-Seidel (4) calculate and display the required results using Gauss-Jacobi"
I need from the above question 4 menu that the user can click from.
Also i would be grateful if someone could tell me how i modify the codes for any particular menu(i worked in Visual Basic 6.0 where interfaces are much easier than python)
Thnx again.
python Syntax (Toggle Plain Text)
I have done some modification to show you how to add it: For more info you can consider www.zetcode.com. BTW any Python IDE can do it if only wxpython is installed import wx class TextEditor(wx.Frame): def __init__(self, parent, id, title): wx.Frame.__init__(self, parent, id, title, size=(350, 600)) # self/Text editor is now a Window with all attribute of a frame # create status bar self.CreateStatusBar() # set default status bar string self.SetStatusText("For help press F1") # define sizers vbox = wx.BoxSizer(wx.VERTICAL) hbox = wx.BoxSizer(wx.HORIZONTAL) #Add menu #define menubar and menu menubar = wx.MenuBar() # attach menubar to the frame self.SetMenuBar(menubar) #define menus filemenu = wx.Menu() #Add any other menu using same trick eg. help = wx.Menu() or print = wx.Menu() # Append items to menu predefined (For now file menu) filemenu.Append(-1, "&New", "New Blank file") # same for help menu i.e help.Append(menu id, menu caption, status bar text ) #----------------------------------------------- # Append a separator -- line to separate menus filemenu.AppendSeparator() #Print menu filemenu.Append(-1, "&Print", "Print file") #------------------------------------------------------- #Append print menu to menubar menubar.Append(filemenu, "&File") # also menubar.Append(menu name, caption) # Note: as in VB, & is for ALT+F #------------------------------------ #center the window self.Center() #show the window(without this the windows will not show up) self.Show(True) #our main application app = wx.App(False) TextEditor(None, -1, "Text Editor") app.MainLoop()
Have that helped you??
![]() |
Similar Threads
- Starting Python (Python)
- I do not want to Exit Python from the title 'x'! (Python)
- here it is (Python)
- here it is (Python)
- Python for Birthday (but having tech difficulties) (Python)
- wx.Menu() (Python)
- How to create Help in wxPython? (Python)
- how to create a submenu in python? (Python)
Other Threads in the Python Forum
- Previous Thread: use button
- Next Thread: Need help with strings
Views: 4332 | Replies: 9
| Thread Tools | Search this Thread |
Tag cloud for Python
approximation array beginner book builtin change cipher clear client code color converter countpasswordentry cturtle curved def dictionary drive dynamic examples excel file float format ftp function gui homework import inches input java library line lines linux list lists loop microcontroller mouse mysqldb mysqlquery newb number numbers output parsing path plugin port prime program programming projects py2exe pygame pymailer pyqt python random recursion recursive redirect remote script scrolledtext search singleton socket sqlite ssh string strings strip subprocess sum syntax table terminal text textarea thread threading time tkinter tlapse tuple tutorial twoup ubuntu unicode urllib urllib2 variable vigenere wikipedia windows wxpython xlwt






