I’m wanting to keep a Frame square (like a chess board). It can be resized. Here is what I tried. It keeps the Frame square, but it won’t decrease in size. It will only increase in size.
import wx
class MainWindow (wx.Frame):
def __init__ (self):
wx.Frame.__init__(self, None)
self.Bind(wx.EVT_SIZE, self.OnSize)
self.Show()
def OnSize (self, event):
w,h = self.GetClientSize()
size = max(w,h)
self.SetClientSize((size,size))
if __name__ == '__main__':
app = wx.PySimpleApp()
win = MainWindow()
app.MainLoop()
(Copied from my comment as suggested by RobinDunn)
The problem is that
max(w, h)will always return the largest number. So if you are decreasing the size horizontally, the vertical size will overrule the horizontal size. So ideally, you would want to know what changed inOnSize, so you can deduce what the user intent was (increase or decrease), and usemin/maxaccordingly. One idea is to store the previous size on the frame, so you can compare the new and previous size.The idea is something like the code below. Note that it is still rough around the edges, but
it should give you a starting point.