Hello,
I’ve been struggling now for some time with a few problems which are purely cosmetic, however they still bother me a bit! The problems are illustrated in the attached script.
-
In the script I’m using a GridBagSizer to position the widgets in the frame. I have a ListBox which spans two rows and is initially empty. Upon pressing the Load button, the ListBox is populated and everything looks fine. However afterwards when the Layout button is pressed, the size of the ListBox changes and messes up the whole screen. Is this a bug, or am I doing something wrong? Is there a way to make the ListBox keep the same size even when Layout() is called?
-
My other question is regarding wx.Choice and wx.ComboBox. As can be seen from my example, the default size settings for these two are quiet different. wx.ComboBox seems to have a set large width regardless of what its value is, while the width of wx.Choice depends on its initial value. Is there a way to get the same size for all these widget on a page without having to explicitly give size=(x,y) in their definition? I know that in this case I could use flag=wx.EXPAND since they are in the same column, but I’m wondering regarding a more general case.
-
Is there a command which resets a given GUI and sets the values of all the widgets back to the initial state as if the program has been just opened? Currently I’m resetting every widget one by one, but I was wondering if there is a smarter and quicker way to accomplish the same task.
Thanks a lot in advance for any help and suggestions.
#!/usr/bin/env python
import wx
class MyExampleClass(wx.Frame):
def init(self,parent,id):
wx.Frame.__init__(self,parent,id)
self.main_sizer = wx.GridBagSizer(hgap=10, vgap=10)
self.example_listbox = wx.ListBox(self, -1, choices=[], style=wx.LB_ALWAYS_SB)
load_list_btn = wx.Button(self, -1, label='Load')
layout_btn = wx.Button(self, -1, label='Layout')
self.main_sizer.Add(wx.StaticText(self, -1, label='This is an example'), pos=(0,0))
self.main_sizer.Add(self.example_listbox, pos=(1,0), span=(2,1), flag=wx.EXPAND)
self.main_sizer.Add(load_list_btn, pos=(1,1))
self.main_sizer.Add(layout_btn, pos=(2,1))
self.main_sizer.Add(wx.ComboBox(self, -1, value='example', choices=['example']), pos=(1,2))
self.main_sizer.Add(wx.ComboBox(self, -1, value='longer example', choices=['longer example']), pos=(2,2))
self.main_sizer.Add(wx.Choice(self, -1, choices=['example']), pos=(3,2))
self.main_sizer.Add(wx.Choice(self, -1, choices=['longer example']), pos=(4,2))
self.Bind(wx.EVT_BUTTON, self.load_values, load_list_btn)
self.Bind(wx.EVT_BUTTON, self.frame_layout, layout_btn)
self.SetSizer(self.main_sizer)
self.main_sizer.Fit(self)
def load_values(self,event):
list_values = []
for n in range(6):
list_values.append('value ’ + str(n))
self.example_listbox.Set(list_values)
def frame_layout(self,event):
self.main_sizer.Layout()
if name==‘main’:
app=wx.App()
mainframe=MyExampleClass(parent=None,id=-1)
mainframe.Show()
app.MainLoop()