#1
  1. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154

    wxPython Problems!


    This is becoming very annoying and I have no clue how to fix this. For some reason I cannot position items that I add to my program in wxPython. Whenever I create a textc control, listbox, or statictext, they can't be positioned. The statictext just appears at the very top left hand corner of the window, and if I use text control or a listbox, it covers the entire window. It seems there is no way to fix this. I look at the wxPython demos and their code is slightly different than mine. Here is what my main code looks like. I'll leave out all the functions that don't need to be shown.
    Code:
    class MainFrame(wxFrame):
        def __init__(self, parent, id, title):
            wxFrame.__init__(self, parent, id, title,
                             wxDefaultPosition, wxSize(600, 350))
            #logger = wxTextCtrl(self,5, '',wxPoint(300,20), wxSize(200,300),wxTE_MULTILINE | wxTE_READONLY)
            self.label = wxStaticText(self, -1, "Offline (0)", wxPoint(50, 50))
            sb = self.CreateStatusBar(2)
            sb.SetStatusWidths([-1, 156])
            self.timer = wxPyTimer(self.Notify)
            self.timer.Start(1000)
            self.Notify()
            self.SetStatusText('PythonBot - Build 1001')
            menu = wxMenu()
            menu.Append(ID_ABOUT, '&About', 'Brief description of sLBot')
            menuBar = wxMenuBar()
            menuBar.Append(menu, '&File');
            menu2 = wxMenu()
            menu2.Append(ID_CONNECT, '&Connect', 'Connect to Battle.net')
            menu2.Append(ID_DISCONNECT, '&Disconnect', 'Disconnect from Battle.net')
            menu2.Append(ID_RECONNECT, '&Reconnect', 'Reconnect to Battle.net')
            menu3 = wxMenu()
            menu3.Append(ID_SETUP, '&Setup', 'Open setup.txt')
            menu3.Append(ID_OPTIONS, '&Options', 'Open options.txt')
            menu3.Append(ID_ACCESS, '&Access', 'Open access.txt')
            menu3.Append(ID_SAFELIST, '&Safelist', 'Open safelist.txt')
            menu3.Append(ID_****LIST, '&****list', 'Open ****list.txt')
            menu3.Append(ID_TAGBANS, '&Tagbans', 'Open tagbans.txt')
            menu3.Append(ID_BNETLOG, '&BnetLog', 'Open bnetlog.txt')
            menuBar.Append(menu2, '&Connections');
            menuBar.Append(menu3, '&Database Files');
            self.SetMenuBar(menuBar)
            EVT_MENU(self, ID_ABOUT, self.OnAbout)
            EVT_MENU(self, ID_SETUP, self.OnSetup)
            EVT_MENU(self, ID_OPTIONS, self.OnOpt)
            EVT_MENU(self, ID_ACCESS, self.OnAccess)
            EVT_MENU(self, ID_SAFELIST, self.OnSafe)
            EVT_MENU(self, ID_****LIST, self.On****)
            EVT_MENU(self, ID_TAGBANS, self.OnTag)
            EVT_MENU(self, ID_BNETLOG, self.OnLog)
    class BotFrame(wxApp):
        def OnInit(self):
            frame = MainFrame(NULL, -1, 'sLBot - By Yegg')
            frame.Show(true)
            self.SetTopWindow(frame)
            return true
    app = BotFrame(0)
    app.MainLoop()
    Whenever I try doing something like this:
    Code:
    wxStaticText(self,-1,"put something here",wxPoint(20, 50))
    It just appears in the top left hand corner of the window, NEVER anywhere else. What is wrong with my code?

    Update: Well, right after I posted I figured out how to make it work. However I have to add the same thing twice with a different name. If anyone knows why, please explain this.
    Last edited by †Yegg†; April 12th, 2005 at 04:22 PM.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2004
    Location
    Bimingham,AL
    Posts
    68
    Rep Power
    11
    I see that you are not using any kind of layout scheme for laying out your contols. wxpython needs that you specify layout scheme to layout your controls.
    Please refer to sizers and stuff for more on that.
  4. #3
  5. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    I didn't know I needed any of that. Anyways, everything seems to be working fine and I can move objects to the proper area without a problem. It's just that if I remove my second statictext, everything gets messed up. That's probably why it's having this problem, it doesn't have a layout scheme.
  6. #4
  7. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Location
    Cambridge, UK
    Posts
    783
    Rep Power
    14
    Unless you explicitly define the layout wxPython will just be guessing (using defaults) what rules to apply

    Have you tried Boa Constructor ? This is an IDE that gives you drag and drop wxPython development. It does a lot of the hard work managing layout for you.


    grim
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Thank's for the link Grim. I've never heard of Boa Constructor before. Even though it looks and seems easier, I think I'm going to stay with wxPython.

IMN logo majestic logo threadwatch logo seochat tools logo