gpt4 book ai didi

python - wxPython:调整笔记本内笔记本的大小

转载 作者:太空宇宙 更新时间:2023-11-03 19:23:34 24 4
gpt4 key购买 nike

我制作了一个 GUI,其中有 4 个主要选项卡,然后这 4 个选项卡被分成两半,左侧有另一个笔记本,右侧有一个空面板(此处将显示一个图表)。请参阅下面我的 GUI 的图片。 enter image description here

我遇到的问题是我无法调整左侧笔记本的大小以适应笔记本的内容。通过调整其内容,我的意思是我希望将笔记本的右侧拉入。我还希望大小保持固定,因此如果我通过单击并拖动右侧角来调整窗口大小,它不会调整笔记本的大小,但右侧面板将根据用户是否单击并拖动而变大/变小。

代码如下:

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()

最佳答案

检查此代码,了解添加到容器大小调整器时如何为小部件指定比例,以便生成您想要的内容。
您必须将面板比例设置为 1(占据小部件所有可用空间的 100%),并将笔记本比例设置为 0(占据容纳其子小部件所需的最小空间):

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade HG on Sat Jan 21 15:09:27 2012

import wx

# begin wxGlade: extracode
# end wxGlade

class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
self.notebook_1 = wx.Notebook(self, -1, style=0)
self.notebook_1_pane_1 = wx.Panel(self.notebook_1, -1)
self.notebook_2 = wx.Notebook(self.notebook_1_pane_1, -1, style=0)
self.notebook_2_pane_1 = wx.Panel(self.notebook_2, -1)
self.button_1 = wx.Button(self.notebook_2_pane_1, -1, "button_1")
self.notebook_2_pane_2 = wx.Panel(self.notebook_2, -1)
self.panel_1 = wx.Panel(self.notebook_1_pane_1, -1)
self.notebook_1_pane_2 = wx.Panel(self.notebook_1, -1)
self.notebook_1_pane_3 = wx.Panel(self.notebook_1, -1)

self.__set_properties()
self.__do_layout()
# end wxGlade

def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle("frame_1")
self.panel_1.SetBackgroundColour(wx.Colour(255, 255, 0))
# end wxGlade

def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
sizer_3 = wx.BoxSizer(wx.VERTICAL)
sizer_3.Add(self.button_1, 0, 0, 0)
self.notebook_2_pane_1.SetSizer(sizer_3)
self.notebook_2.AddPage(self.notebook_2_pane_1, "tab1")
self.notebook_2.AddPage(self.notebook_2_pane_2, "tab2")

sizer_2.Add(self.notebook_2, 0, wx.EXPAND, 0) #<- notebook,proportion 0
sizer_2.Add(self.panel_1, 1, wx.EXPAND, 0) #<- panel, proportion 1

self.notebook_1_pane_1.SetSizer(sizer_2)
self.notebook_1.AddPage(self.notebook_1_pane_1, "tab1")
self.notebook_1.AddPage(self.notebook_1_pane_2, "tab2")
self.notebook_1.AddPage(self.notebook_1_pane_3, "tab3")
sizer_1.Add(self.notebook_1, 1, wx.EXPAND, 0)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()
# end wxGlade

# end of class MyFrame


if __name__ == "__main__":
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_1 = MyFrame(None, -1, "")
app.SetTopWindow(frame_1)
frame_1.Show()
app.MainLoop()

enter image description here

关于python - wxPython:调整笔记本内笔记本的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8953513/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com