我编写的代码构成了顶部和底部面板,我需要添加一个左面板,如下图所示:
我当前的代码是:
import wx
class MainFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,title="myapp",size=(800,580))
self.split_win =wx.SplitterWindow(self)
self.top = wx.Panel(self.split_win ,style = wx.SUNKEN_BORDER)
self.bottom = wx.Panel(self.split_win ,style = wx.SUNKEN_BORDER)
self.split_win.SplitHorizontally(self.top,self.bottom,450)
st1 = wx.StaticText(self.bottom, -1, "This is an example of static text", (20, 10))
self.bottom.SetBackgroundColour('white')
app = wx.App()
frame=MainFrame(None).Show()
app.MainLoop()
我需要像图片中一样的左侧面板,可以在其中添加按钮和组合框。
我还想知道底部面板,左侧面板和顶部面板是否可以不分开?
感谢帮助
答案 0 :(得分:1)
欢迎使用wx.python中的sizers
从这里开始:https://wxpython.org/Phoenix/docs/html/sizers_overview.html
import wx
class MainFrame(wx.Frame):
def __init__(self,parent):
wx.Frame.__init__(self,parent,title="myapp",size=(800,580))
self.top = wx.Panel(self, style = wx.SUNKEN_BORDER)
self.bottom = wx.Panel(self ,style = wx.SUNKEN_BORDER)
self.left = wx.Panel(self ,style = wx.SUNKEN_BORDER, size = (150,-1))
st1 = wx.StaticText(self.bottom, -1, "This is an example of static text")
st2 = wx.StaticText(self.left, -1, "Left Panel", (20, 10))
self.bottom.SetBackgroundColour('white')
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer1.Add(self.top,1,wx.EXPAND,5)
sizer1.Add(self.bottom,1,wx.EXPAND,5)
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
sizer2.Add(self.left,0,wx.EXPAND,5)
sizer2.Add(sizer1,1,wx.EXPAND,5)
self.SetSizer(sizer2)
app = wx.App()
frame=MainFrame(None).Show()
app.MainLoop()