Resize wxPython window

Is it possible to make a wxPython window only re-meaningful for a particular relationship? I know that you can turn off resizing; however, I would like it to depend on a certain ratio of width and height when resizing a window.

+5
source share
2 answers

One obvious way to do this would be to attach wx.EVT_SIZEto a function that holds back the aspect ratio. I'm not sure if this is the right way to do this, but it works:

import wx

class SizeEvent(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)

        self.Bind(wx.EVT_SIZE, self.OnSize)
        self.Centre()
        self.SetSizeWH(400, 300)
        self.Show(True)

    def OnSize(self, event):
        hsize = event.GetSize()[0] * 0.75
        self.SetSizeHints(minW=-1, minH=hsize, maxH=hsize)
        self.SetTitle(str(event.GetSize()))

app = wx.App()
SizeEvent(None, 1, 'sizeevent.py')
app.MainLoop()

(The template is borrowed from here .)

+6
source

wxPython, reset / , , ? ?

-1

All Articles