在网上寻找了很久一直没有找到关于wxpython的界面切换的确切的代码,也有些代码写的太高深了看不懂,经过搜索知道了可以利用wxpython的布局sizer,完成点击按钮切换界面,于是自己便试着去写了一下最后粗糙的实现了这一功能。
import wx
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, size=(400, 500))
self.Center()
# 创建一个grid布局参数(rows, cols, vgap, hgap) 行数、列数、垂直间隔、水平间隔
self.sizer = wx.GridSizer(5, 1, 0, 0)
# 创建两个按钮
button1 = wx.Button(self, label='按钮1')
button1.Bind(wx.EVT_BUTTON, self.change1)
button2 = wx.Button(self, label='按钮2')
button2.Bind(wx.EVT_BUTTON, self.change2)
button3 = wx.Button(self, label='按钮3')
button3.Bind(wx.EVT_BUTTON, self.change3)
self.panel1 = wx.Panel(self)
self.panel1.SetBackgroundColour('red')
self.panel2 = wx.Panel(self)
self.panel2.SetBackgroundColour('blue'