我使用wxpython创建了一个窗口,并且设置了一个标签页,但当我使用 Fit 自动设置窗口大小时,会适应最大的标签页。
希望能够根据我点击标签页自动变换窗口大小,以下是代码。
我知道可以通过setsize 重新设置大小,但是我好奇 Fit 能否根据标签页大小变化而不是吃到大的那页
import wx
class main_label(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'CN payment',
style=wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.SYSTEM_MENU
)
self.mnotebook = MyNotebook(self)
self.mnotebook.Show()
bs = wx.BoxSizer(wx.VERTICAL)
bs.Add(self.mnotebook, 1, wx.EXPAND)
self.SetSizer(bs)
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED,self.getid)
## self.Fit()
self.Center()
self.Show()
def getid(self,event):
print(self.mnotebook.GetSelection())
#self.Setsize()
self.Fit()
class MyNotebook(wx.Notebook):
def __init__(self, parent):
self.parent = parent
wx.Notebook.__init__(self, parent)
self.page1 = MyPage1(self)
self.page2 = MyPage2(self)
self.AddPage(self.page1, "EDI")#MyPage加入并命名
self.AddPage(self.page2, "PM")
class MyPage1(wx.Panel):
def __init__(self,parent):
wx.Panel.__init__(self, parent)
self.parent = parent
self.text1 = wx.StaticText(self, -1, '目标文件', pos=(150, 35))
self.textctrl1 = wx.TextCtrl(self, -1, '请输入正确的URL地址', pos=(150, 50), size=(260, 25),
style=wx.TE_READONLY)
self.inputbt1 = wx.Button(self, -1, 'a', pos=(415, 50), size=(70, 25))
self.usebt1 = wx.Button(self, -1, 'eeeeeer', pos=(110, 100), size=(150, 25))
self.usebt2 = wx.Button(self, -1, 'aaaa', pos=(390, 100), size=(110, 25))
self.usebt3 = wx.Button(self, -1, 'sdasad', pos=(270, 100), size=(110, 25))
self.SetBackgroundColour('white')
class MyPage2(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.parent = parent
vbox = wx.BoxSizer(wx.VERTICAL) #顶层
nm0 = wx.StaticBox(self, -1, 'edaa:')
nm0Sizer = wx.StaticBoxSizer(nm0, wx.HORIZONTAL)
nmbox0 = wx.BoxSizer(wx.HORIZONTAL)
self.tc0 = wx.TextCtrl(self,-1,'ssa',size = (50,-1))
nmbox0.Add(self.tc0, 0, wx.ALL | wx.CENTER, 15)
self.tc1 = wx.TextCtrl(self, -1, "import sourcefile", size=(200, -1),style = wx.TE_READONLY)
nmbox0.Add(self.tc1, 0, wx.ALL | wx.CENTER, 15)
self.btn1 = wx.Button(self, -1, 'Import')
nmbox0.Add(self.btn1, 0, wx.ALL | wx.CENTER, 5)
nm0Sizer.Add(nmbox0, 0, wx.ALL | wx.CENTER, 10)
nmbox1 = wx.BoxSizer(wx.HORIZONTAL)
self.btn2 = wx.Button(self, -1, 'ddddddddddmber')
self.btn3 = wx.Button(self, -1, 'dddddddddd')
nmbox1.Add(self.btn2, 0, wx.ALL | wx.CENTER, 5)
nmbox1.Add(self.btn3, 0, wx.ALL | wx.CENTER, 5)
nmbox2 = wx.BoxSizer(wx.HORIZONTAL)
self.btn4 = wx.Button(self, -1, 'dddddddddd')
self.btn5 = wx.Button(self, -1, 'ddddddddddddddd')
nmbox2.Add(self.btn4, 0, wx.ALL | wx.CENTER, 5)
nmbox2.Add(self.btn5, 0, wx.ALL | wx.CENTER, 5)
vbox.Add(nm0Sizer, 0, wx.ALL | wx.CENTER, 5)
vbox.Add(nmbox1, 0, wx.ALL | wx.CENTER, 5)
vbox.Add(nmbox2, 0, wx.ALL | wx.CENTER, 5)
self.SetSizer(vbox)
if __name__ == '__main__':
app = wx.App() # 创建应用程序对象
login = main_label()
app.MainLoop()