Reputation: 45
I have created a wx.frame class
with wxpython
.
I'd like to change the frame's
size inside the class, is it possible?
i know set the frame's
size when init
, like
class MyFrame(wx.Frame):
def __init__(self):
super(MyFrame,self).__init__(None, -1, title="demo", size=(width, height))
def change_frame_size(self)
I'd like to create a function inside the class, which can change the frame's size to maximum. anybody knows?
Upvotes: 3
Views: 4416
Reputation: 22443
Just use SetSize()
e.g.
import wx
class MyApp(wx.App):
def OnInit(self):
self.frame = MyFrame()
self.SetTopWindow(self.frame)
return True
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self,None, title="Window", pos = (100,150), size =(250,200))
menu = wx.Menu()
menu.Append(1,'&Resize Max')
menu.AppendSeparator()
menu.Append(2,'Resize &Min')
menu.AppendSeparator()
menu.Append(3,'E&xit')
menuBar = wx.MenuBar()
menuBar.Append(menu,'&File')
self.Bind(wx.EVT_MENU, self.OnMax, id=1)
self.Bind(wx.EVT_MENU, self.OnMin, id=2)
self.Bind(wx.EVT_MENU, self.OnExit, id=3)
self.SetMenuBar(menuBar)
self.SetMaxSize((500,400))
self.SetMinSize((250,200))
self.Layout()
self.Show()
def OnExit(self, evt):
self.Destroy()
def OnMax(self, evt):
self.SetSize(self.MaxSize)
print("MyFrame resized bigger!")
def OnMin(self, evt):
self.SetSize(self.MinSize)
print("MyFrame resized smaller!")
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
Upvotes: 1
Reputation: 2034
SetSize
method can be used to change the size of a window.
def change_frame_size(self, width, height):
self.SetSize(wx.Size(width, height))
In order to maximize a window, you have Maximize
method.
self.Maximize()
Upvotes: 3