[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] wx Menu



I got the following code:

import wx

class SimpleDemo(wx.Frame):
    def __init__(self, parent):

        # Any variable with the equals after it is optional
        wx.Frame.__init__(self, parent, -1, "Window title", size=(300, 200), pos = (50, 50))

        # Define the panel so we can place things on it
        #panel = wx.Panel(self, -1)

        ###########
        # MENU BAR
        ###########

        # First define the menubar object
        menubar = wx.MenuBar()

        # Now define our pulldown menus.
        file_menu = wx.Menu()

        about = wx.MenuItem(file_menu, 2, '&About') # note the id's (2 in this case) must match in the binding below
        self.Bind(wx.EVT_MENU, self.OnDummy, id=2)   # This is the binding, which tells Python what to do when someone clicks that entry. The function name (OnDummy in this case) can be anything, but the function must exist.
        file_menu.AppendItem(about) # add it to the file menu

        file_menu.AppendSeparator() # a separator, strictly cosmetic

        quit_item = wx.MenuItem(file_menu, 3, 'Quit!')
        self.Bind(wx.EVT_MENU, self.OnDummy, id=3) # again, binding an action. Note that the function name (OnQuit) can be anything, but must exist.
        file_menu.AppendItem(quit_item)

        # Another pulldown menu         
        help_menu = wx.Menu()

        help_item = wx.MenuItem(help_menu, 4, 'Help')
        self.Bind(wx.EVT_MENU, self.OnDummy, id=4)
        help_menu.AppendItem(help_item)

        menubar.Append(file_menu, '&File   ')
        menubar.Append(help_menu, 'Help   ')
       
        self.SetMenuBar(menubar)

        self.Show()


    def OnDummy(self, event):
        print "Clicked!"

It works; drawing a menubar.  Is there a way to do it in a pygame window?
Thanks,
Ian