Is there any way to set the maximum size of a ListBox (by pixels)? I know that there is a SetMaxSize but it is not enforced.

7 Years
Discussion Span
Last Post by phunehehe

It is already in a sizer. The ListBox is empty to begin with. Then from user input, I add a list of numbers, which does not change the size. However, if the Frame is resized the ListBox become too big, and shrinks the Panels around it. SetMaxSize doesn't seem do anything to stop it from growing.


Here is the code in the immediate panel.

self.record_numbers = wx.ListBox(self, -1, choices=[], 
self.record_numbers.SetMinSize((50, -1))
self.record_numbers.SetMaxSize((75, -1))

self.sizer_staticbox = wx.StaticBox(
            self, -1, 'Search | Search for "THE SEARCH STRING" retrieved X records')

self.sizer = wx.StaticBoxSizer(self.sizer_staticbox, wx.HORIZONTAL)

self.rlist_sizer = wx.BoxSizer(wx.VERTICAL)
self.rlist_sizer.Add(self.record_numbers, 0, wx.ALL|wx.EXPAND, 3)

self.sizer.AddMany([(self.buttons_sizer, 0, wx.ALL|wx.ALIGN_CENTER, 3),
                            (self.rlist_sizer, 1, wx.ALL, 3),
                            (self.sc_buttons_sizer, 0, wx.ALL|wx.ALIGN_CENTER, 3)])

I'm confused. If it doesn't have the method, then how is it that wx.ListBox.SetMaxSize() is valid code?


I know this is an old thread but I must make this clear. ListBox itself doesn't have a method named SetMaxSize, but it is a descendant of Window so the method is inherited.

I'm still looking for the answer that you asked, so if you have found it already please post :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.