wxPython:调整笔记本内笔记本的大小
我制作了一个 GUI,其中有 4 个主要选项卡,然后这 4 个选项卡被分成两半,左侧有另一个笔记本,右侧有一个空面板(此处将显示一个图表)。请参阅下面的 GUI 图像。
我遇到的问题是我无法在向左以适合笔记本的内容。通过调整其内容,我的意思是我希望将笔记本的右侧拉入。我还希望大小保持固定,因此如果我通过单击并拖动右侧角来调整窗口大小,它不会调整笔记本的大小,但右侧面板将根据用户是否单击并拖动而变大/变小。
代码如下:
import wx
import wx.grid
class MyFrame1(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame1.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.notebook_2 = wx.Notebook(self, -1, style=0)
self.notebook_2_pane_1 = wx.Panel(self.notebook_2, -1)
self.notebook_2_pane_2 = wx.Panel(self.notebook_2, -1)
self.notebook_2_pane_3 = wx.Panel(self.notebook_2, -1)
self.notebook_2_pane_4 = wx.Panel(self.notebook_2, -1)
self.notebook_3 = wx.Notebook(self.notebook_2_pane_1, -1, style=0)
self.notebook_3a = wx.Notebook(self.notebook_3, -1, style=0)
self.notebook_4 = wx.Notebook(self.notebook_3, -1, style=0)
self.panel_2a = wx.Panel(self.notebook_4, -1)
self.panel_2b = wx.Panel(self.notebook_3a, -1)
self.panel_2c = wx.Panel(self.notebook_3a, -1)
self.panel_2 = wx.Panel(self.notebook_3, -1)
self.panel_1 = wx.Panel(self.notebook_2_pane_1, -1)
self.grid_1 = wx.grid.Grid(self.panel_2a, -1, size=(1, 1))
self.grid_2 = wx.grid.Grid(self.notebook_4, -1, size=(1, 1))
self.bws_btn = wx.Button(self.panel_2b, -1, "Browse...")
self.tctrl = wx.TextCtrl(self.panel_2b, -1)
self.filename = wx.StaticText(self.panel_2b, -1, 'File:')
self.limitdata = wx.StaticText(self.panel_2b, -1, 'Limit Data:')
self.tctrl3 = wx.TextCtrl(self.panel_2b, -1, '200')
self.disp_sel_pk = wx.StaticText(self.panel_2c, -1, 'Display Selected Data')
self.toggle = wx.ToggleButton(self.panel_2c, 1, 'Toggle')
self.add_peak = wx.StaticText(self.panel_2c, -1, 'Add Data:')
self.add_peak_tctrl = wx.TextCtrl(self.panel_2c, -1, 'Test')
self.add_peak_btn = wx.Button(self.panel_2c, -1, "Add")
self.capt_click = wx.Button(self.panel_2c, -1, "Capture Mouse Click")
self.save_btn = wx.Button(self.panel_2a, -1, "Save as CSV file")
self.update_btn = wx.Button(self.panel_2a, -1, "Update")
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame1.__set_properties
self.SetTitle("frame_2")
self.SetMinSize((800, 600))
self.grid_1.CreateGrid(30, 3)
self.grid_1.SetRowLabelSize(0) # hide the rows
self.grid_1.SetColLabelValue(0, "Data ID")
self.grid_1.SetColLabelValue(1, "Test")
self.grid_1.SetColLabelValue(2, "Frquency")
self.grid_2.CreateGrid(30, 13)
self.grid_2.SetRowLabelSize(30)
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame1.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
sizer_5.Add(self.filename, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_4.Add(self.bws_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_4.Add(self.tctrl, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_6.Add(self.limitdata, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_6.Add(self.tctrl3, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_1.Add(sizer_5)
sizer_1.Add(sizer_4)
sizer_1.Add(sizer_6)
sizer_1a = wx.BoxSizer(wx.VERTICAL)
sizer_1a.Add(self.grid_1, 1, wx.EXPAND, 0)
sizer_1a.Add(self.save_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_1a.Add(self.update_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
self.panel_2b.SetSizer(sizer_1)
self.panel_2a.SetSizer(sizer_1a)
sizer_1b = wx.BoxSizer(wx.VERTICAL)
sizer_4a = wx.BoxSizer(wx.HORIZONTAL)
sizer_5a = wx.BoxSizer(wx.HORIZONTAL)
sizer_6a = wx.BoxSizer(wx.HORIZONTAL)
sizer_7a = wx.BoxSizer(wx.HORIZONTAL)
sizer_8a = wx.BoxSizer(wx.HORIZONTAL)
sizer_4a.Add(self.disp_sel_pk, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_5a.Add(self.toggle, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_6a.Add(self.add_peak, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_7a.Add(self.add_peak_tctrl, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_7a.Add(self.add_peak_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_8a.Add(self.capt_click, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_1b.Add(sizer_4a)
sizer_1b.Add(sizer_5a)
sizer_1b.Add(sizer_6a)
sizer_1b.Add(sizer_7a)
sizer_1b.Add(sizer_8a)
self.panel_2c.SetSizer(sizer_1b)
self.notebook_3.AddPage(self.notebook_3a, "Inputs")
self.notebook_3.AddPage(self.notebook_4, "Results")
self.notebook_3a.AddPage(self.panel_2b, "Graph")
self.notebook_3a.AddPage(self.panel_2c, "Calc")
self.notebook_4.AddPage(self.panel_2a, "Info")
self.notebook_4.AddPage(self.grid_2, "Info2")
sizer_3.Add(self.notebook_3, 1, wx.EXPAND, 0)
sizer_3.Add(self.panel_1, 1, wx.EXPAND, 0)
self.notebook_2_pane_1.SetSizer(sizer_3)
self.notebook_2.AddPage(self.notebook_2_pane_1, "Setup")
self.notebook_2.AddPage(self.notebook_2_pane_2, "Optimisation")
self.notebook_2.AddPage(self.notebook_2_pane_3, "Algorithm")
self.notebook_2.AddPage(self.notebook_2_pane_4, "Data")
sizer_2.Add(self.notebook_2, 1, wx.EXPAND, 0)
self.SetSizer(sizer_2)
sizer_2.Fit(self)
self.Layout()
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_2 = MyFrame1(None, -1, "")
app.SetTopWindow(frame_2)
frame_2.Show()
app.MainLoop()
I have made a GUI where there are 4 main tabs, the 4 tabs are then split in half, with another notebook on the left and an empty panel on the right (a graph will go here). See image for below of my GUI.
The problem I am having is that I cannot resize the notebook on the left to fit the contents of the notebook. By fitting its contents I mean I want the right hand side of the notebook to be pulled in. I also want the size to remain fixed so If I resized the window by clicking and dragging the right hand corner it wont resize the notebook, but the panel on the right will get bigger/smaller depending on whether the user clicked and dragged.
Code below:
import wx
import wx.grid
class MyFrame1(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame1.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.notebook_2 = wx.Notebook(self, -1, style=0)
self.notebook_2_pane_1 = wx.Panel(self.notebook_2, -1)
self.notebook_2_pane_2 = wx.Panel(self.notebook_2, -1)
self.notebook_2_pane_3 = wx.Panel(self.notebook_2, -1)
self.notebook_2_pane_4 = wx.Panel(self.notebook_2, -1)
self.notebook_3 = wx.Notebook(self.notebook_2_pane_1, -1, style=0)
self.notebook_3a = wx.Notebook(self.notebook_3, -1, style=0)
self.notebook_4 = wx.Notebook(self.notebook_3, -1, style=0)
self.panel_2a = wx.Panel(self.notebook_4, -1)
self.panel_2b = wx.Panel(self.notebook_3a, -1)
self.panel_2c = wx.Panel(self.notebook_3a, -1)
self.panel_2 = wx.Panel(self.notebook_3, -1)
self.panel_1 = wx.Panel(self.notebook_2_pane_1, -1)
self.grid_1 = wx.grid.Grid(self.panel_2a, -1, size=(1, 1))
self.grid_2 = wx.grid.Grid(self.notebook_4, -1, size=(1, 1))
self.bws_btn = wx.Button(self.panel_2b, -1, "Browse...")
self.tctrl = wx.TextCtrl(self.panel_2b, -1)
self.filename = wx.StaticText(self.panel_2b, -1, 'File:')
self.limitdata = wx.StaticText(self.panel_2b, -1, 'Limit Data:')
self.tctrl3 = wx.TextCtrl(self.panel_2b, -1, '200')
self.disp_sel_pk = wx.StaticText(self.panel_2c, -1, 'Display Selected Data')
self.toggle = wx.ToggleButton(self.panel_2c, 1, 'Toggle')
self.add_peak = wx.StaticText(self.panel_2c, -1, 'Add Data:')
self.add_peak_tctrl = wx.TextCtrl(self.panel_2c, -1, 'Test')
self.add_peak_btn = wx.Button(self.panel_2c, -1, "Add")
self.capt_click = wx.Button(self.panel_2c, -1, "Capture Mouse Click")
self.save_btn = wx.Button(self.panel_2a, -1, "Save as CSV file")
self.update_btn = wx.Button(self.panel_2a, -1, "Update")
self.__set_properties()
self.__do_layout()
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame1.__set_properties
self.SetTitle("frame_2")
self.SetMinSize((800, 600))
self.grid_1.CreateGrid(30, 3)
self.grid_1.SetRowLabelSize(0) # hide the rows
self.grid_1.SetColLabelValue(0, "Data ID")
self.grid_1.SetColLabelValue(1, "Test")
self.grid_1.SetColLabelValue(2, "Frquency")
self.grid_2.CreateGrid(30, 13)
self.grid_2.SetRowLabelSize(30)
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame1.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.VERTICAL)
sizer_3 = wx.BoxSizer(wx.HORIZONTAL)
sizer_4 = wx.BoxSizer(wx.HORIZONTAL)
sizer_5 = wx.BoxSizer(wx.HORIZONTAL)
sizer_6 = wx.BoxSizer(wx.HORIZONTAL)
sizer_5.Add(self.filename, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_4.Add(self.bws_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_4.Add(self.tctrl, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_6.Add(self.limitdata, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_6.Add(self.tctrl3, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_1.Add(sizer_5)
sizer_1.Add(sizer_4)
sizer_1.Add(sizer_6)
sizer_1a = wx.BoxSizer(wx.VERTICAL)
sizer_1a.Add(self.grid_1, 1, wx.EXPAND, 0)
sizer_1a.Add(self.save_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_1a.Add(self.update_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
self.panel_2b.SetSizer(sizer_1)
self.panel_2a.SetSizer(sizer_1a)
sizer_1b = wx.BoxSizer(wx.VERTICAL)
sizer_4a = wx.BoxSizer(wx.HORIZONTAL)
sizer_5a = wx.BoxSizer(wx.HORIZONTAL)
sizer_6a = wx.BoxSizer(wx.HORIZONTAL)
sizer_7a = wx.BoxSizer(wx.HORIZONTAL)
sizer_8a = wx.BoxSizer(wx.HORIZONTAL)
sizer_4a.Add(self.disp_sel_pk, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_5a.Add(self.toggle, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_6a.Add(self.add_peak, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_7a.Add(self.add_peak_tctrl, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_7a.Add(self.add_peak_btn, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_8a.Add(self.capt_click, flag=wx.EXPAND | wx.RIGHT | wx.Left | wx.TOP | wx.BOTTOM, border=10)
sizer_1b.Add(sizer_4a)
sizer_1b.Add(sizer_5a)
sizer_1b.Add(sizer_6a)
sizer_1b.Add(sizer_7a)
sizer_1b.Add(sizer_8a)
self.panel_2c.SetSizer(sizer_1b)
self.notebook_3.AddPage(self.notebook_3a, "Inputs")
self.notebook_3.AddPage(self.notebook_4, "Results")
self.notebook_3a.AddPage(self.panel_2b, "Graph")
self.notebook_3a.AddPage(self.panel_2c, "Calc")
self.notebook_4.AddPage(self.panel_2a, "Info")
self.notebook_4.AddPage(self.grid_2, "Info2")
sizer_3.Add(self.notebook_3, 1, wx.EXPAND, 0)
sizer_3.Add(self.panel_1, 1, wx.EXPAND, 0)
self.notebook_2_pane_1.SetSizer(sizer_3)
self.notebook_2.AddPage(self.notebook_2_pane_1, "Setup")
self.notebook_2.AddPage(self.notebook_2_pane_2, "Optimisation")
self.notebook_2.AddPage(self.notebook_2_pane_3, "Algorithm")
self.notebook_2.AddPage(self.notebook_2_pane_4, "Data")
sizer_2.Add(self.notebook_2, 1, wx.EXPAND, 0)
self.SetSizer(sizer_2)
sizer_2.Fit(self)
self.Layout()
if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_2 = MyFrame1(None, -1, "")
app.SetTopWindow(frame_2)
frame_2.Show()
app.MainLoop()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
检查此代码,了解添加到容器大小调整器时如何为小部件指定比例,以便生成您想要的内容。
并将笔记本比例设置为 0(占据容纳其子小部件所需的最小空间):
您必须将面板比例设置为 1(占据小部件所有可用空间的 100%) , sstatic.net/edn89.png" alt="在此处输入图像描述">
Check this code to see how proportions are given to widgets when added to container sizers in order to produce what you want.
You must set the panel proportion to 1 (occupy 100% of all space available for the widget) and the notebook proportion to 0 (occupy the minimal space needed to hold its child widgets):