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

  • Home
  • SEARCH
  • 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 6748043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:31:05+00:00 2026-05-26T12:31:05+00:00

I am having problems with wxpython. When I run the following code, it will

  • 0

I am having problems with wxpython. When I run the following code, it will show the listbox in a small form (it will only show the listbox in about 10×10). I do not know why this is happening and there is not much resources online to help me with this. The listbox will show correctly if i do not add any buttons. Pardon me if it is an easy fix however i am truly stumped. If you do not understand what my problem is, please run the following code and you will see.

import wx

class MyFrame(wx.Frame):
    """make a frame, inherits wx.Frame"""
    def __init__(self,parent,id):

        # create a frame, no parent, default to wxID_ANY
        wx.Frame.__init__(self, parent, id, 'Testing',
            pos=(300, 150), size=(600, 500))
        panel = wx.Panel(self)
        sampleList = ['dsakdsko0', '1', '2', '3', '4']
        listBox = wx.ListBox(panel, -1, (4,3), (100, 60), sampleList, wx.LB_SINGLE)
        listBox.SetSelection(3)

        self.SetBackgroundColour("white")

        wx.Button(self, 1, 'Close', (50, 130))
        wx.Button(self, 2, 'Random Move', (150, 130), (110, -1))

        self.Bind(wx.EVT_BUTTON, self.OnClose, id=1)
        self.Bind(wx.EVT_BUTTON, self.OnRandomMove, id=2)

        # show the frame
        self.Show(True)
        #menu bar
        status=self.CreateStatusBar()
        menubar=wx.MenuBar()
        first=wx.Menu()
        second=wx.Menu()
        first.Append(wx.NewId(),"New","Creates A new file")
        first.Append(wx.NewId(),"ADID","Yo")
        menubar.Append(first,"File")
        menubar.Append(second,"Edit")
        self.SetMenuBar(menubar)

    def OnClose(self, event):
        self.Close(True)

    def OnRandomMove(self, event):
        screensize = wx.GetDisplaySize()
        randx = random.randrange(0, screensize.x - APP_SIZE_X)
        randy = random.randrange(0, screensize.y - APP_SIZE_Y)
        self.Move((randx, randy))

if __name__=='__main__':
    application = wx.PySimpleApp()
    frame=MyFrame(parent=None,id=-1)
    frame.Show()
    # start the event loop
    application.MainLoop()

Thank you very very much.

  • 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-05-26T12:31:06+00:00Added an answer on May 26, 2026 at 12:31 pm

    The problem involves the parents. Your buttons’ parent is the frame while the listbox’s parent is the panel. Give the panel to the buttons as their parent too and the issue will go away. By the way, it’s usually not a good idea to assign your own ID numbers, especially such low ones since those might be used. But if you really want to, then follow these instructions from Robin Dunn’s wxPython book:

    “You can ensure that wxPython does not use your explicit ID elsewhere in the application by calling the global function wx.RegisterId(). To prevent your program from duplicating wxPython
    IDs, you should avoid using ID numbers between the global constants wx.ID_LOWEST and wx.ID_HIGHEST.”

    EDIT: Here’s an example of sorts:

    Change this:

    wx.Button(self, 1, 'Close', (50, 130))
    wx.Button(self, 2, 'Random Move', (150, 130), (110, -1))
    

    to this:

    wx.Button(panel, 1, 'Close', (50, 130))
    wx.Button(panel, 2, 'Random Move', (150, 130), (110, -1))
    

    Then to Register your ids:

    wx.RegisterId(1)
    wx.RegisterId(2)
    

    Personally, I would just create my buttons like this instead:

    closeBtn = wx.Button(panel, wx.ID_ANY, 'Close', (50, 130))
    self.Bind(wx.EVT_BUTTON, self.OnClose, closeBtn)
    randomBtn = wx.Button(panel, wx.ID_ANY, 'Random Move', (150, 130), (110, -1))
    self.Bind(wx.EVT_BUTTON, self.OnRandomMove, randomBtn)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im having problems with the following code: for (var i:Number=0; i<numFaces;i++){ var faceLoader:Loader =
am having problems with some Regex code can anyone help. I have the following
Am having problems with the following code reporting an 'invalid argument' in IE6. function
Having problems with a small awk script, Im trying to choose the newest of
Am having problems with PHP's require_once, require, include_once and include functions not correctly resolving
Having problems getting the different arrays content from geocoder results. item.formatted_address works but not
Having problems getting glassfish to even run on my server. jRuby is absoutely maddening
I am having problems with ga.js not loading sometimes. In firebug it just shows
i having problems using this code in order to include a photo in my
having problems trying to run by unit test with Ant, my test class uses

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.