Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8423349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:42:03+00:00 2026-06-10T03:42:03+00:00

This is driving me nuts. I usually use Tkinter for gui stuff, but just

  • 0

This is driving me nuts. I usually use Tkinter for gui stuff, but just felt like actually trying to learn wxpython.

I can’t for the life of me figure out why when I add items like buttons or static text to a panel, using a boxsizer. It just seems to cram everything into position (0,0) on the panel called “side” heres my code.

    import wx

    def AddUser():
        ex = wx.App()
        Stylex = wx.SYSTEM_MENU|wx.CAPTION|wx.CLOSE_BOX
        window = wx.Frame(None, style=Stylex)

        splitter = wx.SplitterWindow(window, -1)
        vbox = wx.BoxSizer(wx.VERTICAL)
        """
        LEFT PANEL... Contains Navigation Tree
        """
        fgs = wx.FlexGridSizer(2,1,5,10) # fgs(int rows, int cols, int vgap, int hgap

        panel = wx.Panel(splitter, -1)
        panel.SetBackgroundColour('#ededed')

        side = wx.Panel(splitter, -1)
        side.SetBackgroundColour('#4f5049')

        multi_btn = wx.Button(panel, label="Batch User Mode")
        multi_btn.SetId(50)

        single_btn = wx.Button(panel, label="Single User Mode")
        single_btn.SetId(25)

        items = [multi_btn,single_btn]

        fgs.AddMany(items)
        vbox.Add(fgs)

        panel.SetSizer(vbox)
        splitter.SplitVertically(panel, side,100)

        """
        SIDE panel...  Contains all widgets
        """
        st = wx.StaticText(side, label="Select a Mode", pos=wx.Point(20,100))
        st.SetForegroundColour(wx.WHITE)

        def SetMode(event):
            """
            25 returned if Single user mode
            50 returned if Batch user mode
            """
            MODE = event.GetId()

            if MODE == 25:
                try:
                    side.DestroyChildren()
                except: pass

                """
                Problem adding items to the dynamnic changing 'SIDE' panel
                """
                vb = wx.BoxSizer(wx.VERTICAL)

                stFName = wx.StaticText(side, id=2,label="First Name:")
                stFName.SetForegroundColour(wx.WHITE)
                vb.Add(stFName)
                tcFName = wx.TextCtrl(side, id=4)
                vb.Add(tcFName)

                stLName = wx.StaticText(side,id=6, label="Last Name:")
                vb.Add(stLName)
                tcLName = wx.TextCtrl(side, id=8)
                vb.Add(tcLName)

                vb.Add(side, 1, flag=wx.EXPAND|wx.ALL, border=5)

                side.SetSizer(vb)

                """
                END Problem
                """
            if MODE == 50:
                try:
                    side.DestroyChildren()
                except: pass
                """
                do the same thing as single user creation, except adding listboxes instead of textctrl's
                """
            return

        multi_btn.Bind(wx.EVT_BUTTON, SetMode)
        single_btn.Bind(wx.EVT_BUTTON, SetMode)

        window.SetTitle('User Creation Process')
        window.Centre()
        window.Show(True)

        ex.MainLoop()

    if __name__=='__main__':
        AddUser()

Thanks very much for any help… I’m sure its something small that I overlooked, but I would like to understand if its a fundamental problem.

Randy

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:42:05+00:00Added an answer on June 10, 2026 at 3:42 am

    That’s the default placement. Sizers are NOT for absolute positioning. If you want to, you can do that by passing a position in each widget. If you want your widgets centered on the left, then you’ll need to but the vertical BoxSizer inside of a horizontal one and center it. Or you can use a couple of Spacers by using AddSpacer or by just adding a size:

    mySizer.Add((10, 20), 0, wx.ALL, 5)
    

    You can also use the “border” parameter of the Sizer’s Add method to control placement to some degree using wx.TOP, wx.BOTTOM, wx.RIGHT or wx.LEFT and giving it the appropriate amount of space. If you are seeing the widgets getting stacked, then you’ll need to add a Layout call at the end (probably from the panel or the frame).

    UPDATE: If you want to swap out panels, I would recommend just hiding and showing them or destroying and creating panels. I wrote up a tutorial on switching panels that might help: http://www.blog.pythonlibrary.org/2010/06/16/wxpython-how-to-switch-between-panels/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me nuts, maybe I'm missing something but I'm trying to upgrade
This is driving me nuts - I want to just display a hash symbol
This is driving me nuts. What happens with width:100% ? Apparently it just works
This is driving me nuts!@#!@# I can load the tinyMce plugin for jquery just
I don't know why this is driving me nuts but it is. I have
This is driving me nuts... I have an input string like so: String input
This is driving me nuts. I have a simple spring app with just a
This is driving me nuts. I am trying to set a background image to
Ok, this is driving me nuts. I've done just about everything I can to
OK, this is driving me nuts. I'm trying to screen-scrape the following bit of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.