Can someone guide me how to make menu in python please?

http://www.daniweb.com/forums/post693793.html#post693793

This is a previous post of what sort of menu i need.

Can someone just give me a start please.

Cheers

Recommended Answers

All 10 Replies

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

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()

Hope that helps!

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()

thnx and to jlm699 im sory fot the pm but i've google it already and im not getting any help because im using Dr python which has wxPython integrated.

Can i know how to modify the above codes so that i can add something to it plz.

Thnx again

what do you need to add?

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.

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??

Can u give me the codes for the above menu i mean with the questions i gave?

Also i want to know who to modify menu that i add?

Your asking for a full code solution to your assignment? I think you may be going wrong there

Chris

Hi, i'm using PythonWin. When i used ur code which import wx, shows error: No module named wx.
I hope U will help me, i'm pretty new in programming in python.
Btw. sorry for my english.

EDIT: is there any method to create "switch...case" like in C ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.