first of all, I know there is a grid layout in wxPython.
But I try to mimic wNim’s Layout DSL with kiwisolver firstly. Then the ultimate goal is to coin Autolayout in wxPython which is more concise to describe GUI layout; which is very hard for me now, so it could be better that the community can make one.
Let’s go back to my question. In the code, the position and size of widget should be recalculated when the user resize the frame. In my simplified code, a button named b1 is placed on the frame. The horizontal gaps between button and frame are 10, the vertical gaps are 5.
if I commented out self.Bind(wx.EVT_SIZE, self.OnResize, self)
, the button with default size will be created. However if self.Bind(wx.EVT_SIZE, self.OnResize, self)
is used, there is no button displayed. So what is the problem?
Thanks
import wx
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title,
size=(350, 300))
self.InitUI()
self.Bind(wx.EVT_SIZE, self.OnResize, self)
self.Centre()
def OnResize(self, evt):
self.w = self.panel.GetSize()[0]
self.h = self.panel.GetSize()[1]
self.b1_w = self.w - 10 * 2
self.b1_h = self.h - 5 * 2
self.b1_x = 10
self.b1_y = 5
print((self.b1_x, self.b1_y))
print(self.b1_w, self.b1_h)
self.b1.SetPosition((self.b1_x, self.b1_y))
self.b1.SetSize(wx.Size(self.b1_w, self.b1_h))
self.b1.Update()
print(dir(self.b1))
self.Refresh()
evt.Skip()
def InitUI(self):
self.panel = wx.Panel(self)
self.b1 = wx.Button(self.panel, wx.ID_ANY, "hello")
def main():
app = wx.App()
ex = Example(None, title='Absolute positioning')
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()