我正在构建一个由三个面板和 2 个网格(每个面板中有一个网格)组成的 GUI。我正在努力使用 BoxSizer 将对象放入各自的面板中。似乎垂直 boxsizer 只考虑了框架的上部和下部,而没有考虑到上部被分成两个面板。因此,我在尝试在上部垂直组织小部件时遇到问题。尝试将小部件添加到 panelTwo 时,垂直放置从 panelOne 拾取,反之亦然。如果可能,我想为每个面板分配一个垂直 boxsizer。请原谅草率的代码。我才刚接触 Python 几天,所以放轻松!我愿意接受建议!这是我遇到问题的部分:
p1Sizer = wx.BoxSizer(wx.VERTICAL)
p2Sizer = wx.BoxSizer(wx.VERTICAL)
p3Sizer = wx.BoxSizer(wx.VERTICAL)`
p3Sizer.Add(bottom_grid, 1, wx.EXPAND)#,pos=(200,200)
p2Sizer.Add(p1Sizer)
hbox1.Add(st1, flag=wx.ALL, border=5)
hbox1.Add(tc1, flag=wx.ALL, border=10)
hbox2.Add(st2, flag=wx.ALL, border=5)
hbox2.Add(tc2, flag=wx.ALL, border=10)
hbox3.Add(st3, flag=wx.ALL, border=5)
hbox3.Add(tc3, flag=wx.ALL, border=5)
p1Sizer.Add(hbox1,flag=wx.ALIGN_RIGHT)
p1Sizer.Add(hbox2, flag=wx.ALIGN_RIGHT)
p1Sizer.Add(hbox3, flag=wx.ALIGN_LEFT)
如果我包含此行,则 panelTwo 的格式正确。唯一的变化是底部框需要向下移动。见附件。
p2Sizer.Add(0,-120)
如果我删除该行:
但我觉得这不是正确的方法。我还试图找到一种方法来创建两个具有不同行数的单独网格。IE
self.CreateGrid(100, 27)
和...
'self.CreateGrid(5, 27)'
import wx
import wx.grid as gridlib
import pandas as pd
import numpy as np
class MyGrid(gridlib.Grid):
def __init__(self, parent):
"""Constructor"""
gridlib.Grid.__init__(self, parent)
self.CreateGrid(100, 27)
class MasterPanel(wx.Panel):
def __init__(self, parent, color):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.SetBackgroundColour(color)`
class MainPanel(wx.Panel):
def __init__(self, parent):`
"""Constructor"""
wx.Panel.__init__(self, parent)`
topSplitter = wx.SplitterWindow(self)
vSplitter = wx.SplitterWindow(topSplitter)
font = wx.SystemSettings.GetFont(wx.SYS_SYSTEM_FONT)
font.SetPointSize(50)
panelOne = MasterPanel(vSplitter, "light grey")
panelTwo = MasterPanel(vSplitter, "white")
panelThree = MasterPanel(topSplitter,"white")
vSplitter.SplitVertically(panelOne, panelTwo)
vSplitter.SetMinimumPaneSize(300) # 300
vSplitter.SetSashGravity(.5)
topSplitter.SplitHorizontally(vSplitter, panelThree)
topSplitter.SetMinimumPaneSize(200) #200
topSplitter.SetSashGravity(1)
#topSplitter.SetSashGravity(1)
# Assign grid to BOTTOM PANEL
bottom_grid = MyGrid(panelThree)
top_grid= MyGrid(panelTwo)
st1 = wx.StaticText(panelOne, -1,"Name")
st1.SetFont(font)
st2 = wx.StaticText(panelOne, -1,"Date:")
st2.SetFont(font)
st3 = wx.StaticText(panelOne, -1,"Input #:")
st3.SetFont(font)
st4 = wx.StaticText(panelTwo, -1,"From Source:")
st4.SetFont(font)
st5 = wx.StaticText(panelTwo, -1,"Lookup:")
st5.SetFont(font)
st6 = wx.StaticText(panelTwo, -1,"Lookup Value:")
st6.SetFont(font)
tc1 = wx.TextCtrl(panelOne,size=(150,25), value="-enter name-")
tc2 = wx.TextCtrl(panelOne,size=(150,25), value="-enter date-")
tc3 = wx.TextCtrl(panelOne, value="-input item #'")
tc4 = wx.TextCtrl(panelTwo, value="-Search-")
options= ['A','B','C']
combo1 = wx.ComboBox(panelTwo,size=(150,25),value="-Choose Source-",choices=options,
style=wx.LB_SINGLE)
combo2 = wx.ComboBox(panelTwo,size=(150,25),value="-Choose Lookup Type-",choices=options,
style=wx.LB_SINGLE)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
hbox3 = wx.BoxSizer(wx.HORIZONTAL)
hbox4 = wx.BoxSizer(wx.HORIZONTAL)
hbox5 = wx.BoxSizer(wx.HORIZONTAL)
hbox6 = wx.BoxSizer(wx.HORIZONTAL)
p1Sizer = wx.BoxSizer(wx.VERTICAL)
p2Sizer = wx.BoxSizer(wx.VERTICAL)
p3Sizer = wx.BoxSizer(wx.VERTICAL)
p3Sizer.Add(bottom_grid, 1, wx.EXPAND)#,pos=(200,200)
p2Sizer.Add(p1Sizer)
hbox1.Add(st1, flag=wx.ALL, border=5)
hbox1.Add(tc1, flag=wx.ALL, border=10)
hbox2.Add(st2, flag=wx.ALL, border=5)
hbox2.Add(tc2, flag=wx.ALL, border=10)
hbox3.Add(st3, flag=wx.ALL, border=5)
hbox3.Add(tc3, flag=wx.ALL, border=5)
p1Sizer.Add(hbox1,flag=wx.ALIGN_RIGHT)
p1Sizer.Add(hbox2, flag=wx.ALIGN_RIGHT)
p1Sizer.Add(hbox3, flag=wx.ALIGN_LEFT)
#p2Sizer.Add(0,-120)
hbox4.Add(st4, flag=wx.ALL, border=5)
hbox4.Add(combo1, flag=wx.ALL, border=5)
hbox5.Add(st5, flag=wx.ALL, border=5)
hbox5.Add(combo2, flag=wx.ALL, border=5)
hbox6.Add(st6, flag=wx.ALL, border=5)
hbox6.Add(tc4, flag=wx.ALL, border=5)
p2Sizer.Add(hbox4)
p2Sizer.Add(hbox5)
p2Sizer.Add(hbox6)
#p1Sizer.Add(p1, 2, wx.EXPAND)#,pos=(200,200)
p2Sizer.Add(top_grid, 1, wx.EXPAND)#,pos=(200,200)
panelThree.SetSizer(p3Sizer)
panelTwo.SetSizer(p2Sizer)
#panelOne.SetSizer(p1Sizer)
sizer = wx.BoxSizer(wx.VERTICAL)
#sizer.Add(top_grid)
sizer.Add(topSplitter, -1, wx.EXPAND)
#panelTwo.SetSizer(sizer)
self.SetSizer(sizer)
class MainFrame(wx.Frame):
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Hell Yeah",
size=(1600,700))
panel = MainPanel(self)
self.Show() `
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
app.MainLoop()'