Listbox changes size unnecessarily when window is resize.

49 views
Skip to first unread message

Jaideep Singh

unread,
Feb 11, 2018, 8:41:18 AM2/11/18
to wxPython-users
I am having a problem with listbox which expand automatically to a certain amount when the window is resized.
I am attaching a demo code to illustrate the issue.
If you hit "x" button more than four times and try to resize the window a little then listbox expands unnecessarily.
I don't know whether it's default behavior or not. If it is a default behavior, then how can I correct it?
I want the listbox to expand freely like it does when there is no value in it.
demo.py

Dietmar Schwertberger

unread,
Feb 11, 2018, 9:15:22 AM2/11/18
to wxpytho...@googlegroups.com
On 2/11/2018 2:41 PM, Jaideep Singh wrote:
> I want the listbox to expand freely like it does when there is no
> value in it.

I'm not sure what you want to accomplish, but try this modification:

self.mainSizer.Add(self.List, 1, wx.ALL | wx.CENTER | wx.EXPAND, 20)

This makes the list box fill the available space vertically and
horizontally.

Regards,

Dietmar

Jaideep Singh

unread,
Feb 12, 2018, 1:03:58 AM2/12/18
to wxPython-users
Sir,
Thank you, for your reply. Your code above solved my problem, but i'm still not able to implement it in my original code.
I'm attaching my original code for reference. Any help is appreciated.
demo.py

Dietmar Schwertberger

unread,
Feb 12, 2018, 5:25:56 PM2/12/18
to wxpytho...@googlegroups.com
On 2/12/2018 7:03 AM, Jaideep Singh wrote:
Thank you, for your reply. Your code above solved my problem, but i'm still not able to implement it in my original code.
You're welcome!
I'm attaching my original code for reference. Any help is appreciated.

Please try these modifications, i.e. with an explicit minimum size for both list boxes:

        self.panel.Screen1Editable2 = wx.ListBox(self.panel, style = wx.LB_SINGLE, size=(20,20))
        self.panel.Screen2Editable2 = wx.ListBox(self.panel, style = wx.LB_SINGLE, size=(20,20))

I think it behaves better this way. Without the minimum size it could be that the controls are setting their size themselves, depending on the number of entries and this triggers a re-layout. With the explicit sizes, the sizer takes those as base. I'm not 100% sure whether this explanation is correct, though.

You may want to replace your SetFont calls with this one right at the top:

        self.SetFont(wx.Font(12, wx.FONTFAMILY_SWISS, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_NORMAL))

The result is probably the same.

Regards,

Dietmar


Jaideep Singh

unread,
Feb 13, 2018, 1:38:58 AM2/13/18
to wxPython-users
Sir,
Thank you very much. Giving listboxes minimum size fixes my problem.
Your advice for replacing my SetFont calls is also very helpful.

Best Regards,
Jaideep


Reply all
Reply to author
Forward
0 new messages