Thread: wxPython help

    #1
  1. Caress me down
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    Pennsylvania
    Posts
    289
    Rep Power
    511

    wxPython help


    alright i picked this code up off of some tutorial. here it is.

    Code:
    from wxPython.wx import *
    
    ID_ABOUT = 101
    ID_EXIT  = 102
    
    class MyFrame(wxFrame):
        def __init__(self, parent, ID, title):
            wxFrame.__init__(self, parent, ID, title,
                             wxDefaultPosition, wxSize(200, 150))
    
            self.CreateStatusBar()
            self.SetStatusText("This is the statusbar")
            menu = wxMenu()
            menu.Append(ID_ABOUT, "&About",
                        "More information about this program")
            menu.AppendSeparator()
            menu.Append(ID_EXIT, "E&xit", "Terminate the program")
            menuBar = wxMenuBar()
            menuBar.Append(menu, "&File");
            self.SetMenuBar(menuBar)
    
            EVT_MENU(self, ID_ABOUT, self.OnAbout)
            EVT_MENU(self, ID_EXIT,  self.TimeToQuit)
    
        def OnAbout(self, event):
            dlg = wxMessageDialog(self, "This sample program shows off\n"
                                  "frames, menus, statusbars, and this\n"
                                  "message dialog.",
                                  "About Me", wxOK | wxICON_INFORMATION)
            dlg.ShowModal()
            dlg.Destroy()
    
    
        def TimeToQuit(self, event):
            self.Close(true)
    
    
    
    class MyApp(wxApp):
        def OnInit(self):
            frame = MyFrame(NULL, -1, "Hello from wxPython")
            frame.Show(true)
            self.SetTopWindow(frame)
            return true
    
    app = MyApp(0)
    app.MainLoop()
    now the colored parts... what exactly do they do? i changed ID_ABOUT to 110 instead of 101. then when i ran the program and clicked about it worked. then i added some zeros (i think 7) to ID_ABOUT and when i ran the program and clicked about nothing happened.

    what exactly do those ID things do?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Posts
    461
    Rep Power
    24
    those are just place holders for the ids of the elements on the screen. wxPython uses ids to help keep track of each bind.

    it is possible that wxPython wont allow ids that large or that you need to put an L (to signifie that it is a long instead of int) at the end to help the interpriter out.

    Comments on this post

    • Yegg` agrees
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Yup. The number is simply an ID for each menu you use. The number (ID) must be unique and not used anywhere else in the program.

IMN logo majestic logo threadwatch logo seochat tools logo