Listbox changes size unnecessarily when window is resize.

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 (730 Bytes)

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

···

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.

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 (3.66 KB)

You’re welcome!

···

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.

    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

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