rectangletangle
rectangletangle

Reputation: 52911

Resizing a wxPython Window

Is it possible to make a wxPython window only re-sizable to a certain ratio? I know you can disable resizing; however, I'd like it so when the window was resized it stuck to a certain width to height ratio.

Upvotes: 5

Views: 7978

Answers (2)

senderle
senderle

Reputation: 150947

One obvious way to do this would be to bind wx.EVT_SIZE to a function that constrains the aspect ratio. I'm not certain 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 boilerplate is borrowed from here.)

Upvotes: 7

Pwnna
Pwnna

Reputation: 9528

I'm not too familiar with wxPython, but can't you just reset the window size to your max/min size that you want once the user pass that? Preferably in the event that detects resizing?

Upvotes: -1

Related Questions