In the code below, use initially can resize the frame to no smaller
than (200, 200) + the size of the button. But I want to make it
possible to resize the frame to a smaller size if the user press a
button. SetMinSize() here seems not work. How?
import wx
class MyPanel(wx.Panel):
def __init__(self, *a, **kw):
super(MyPanel, self).__init__(*a, **kw)
self.SetBackgroundColour(wx.BLUE)
def shrink(self):
self.SetMinSize((100, 100)) # <-- here seems not work
class MyFrame(wx.Frame):
def __init__(self, *a, **kw):
super(MyFrame, self).__init__(*a, **kw)
self.panel = MyPanel(self, size=(200, 200))
self.btn = wx.Button(self, -1, 'Shrink MinSize')
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.panel, 1, wx.GROW)
sizer.Add(self.btn, 0, wx.GROW)
self.SetAutoLayout(True)
self.SetSizerAndFit(sizer)
self.btn.Bind(wx.EVT_BUTTON, self.on_button)
def on_button(self, evt):
self.panel.shrink()
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame(None)
frame.Show()
app.MainLoop()
···
--
Qiangning Hong
I'm usually annoyed by IDEs because, for instance, they don't use VIM
as an editor. Since I'm hooked to that, all IDEs I've used so far have
failed to impress me.
-- Sybren Stuvel @ c.l.python
Get Firefox! <http://www.spreadfirefox.com/?q=affiliates&id=67907&t=1>