我试图用以下布局创建一个gui:
顶部面板将包含三个数字,三个中间面板将包含文本框,底部面板包含一些按钮
这是我到目前为止所做的:
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
import gui_functions as gf
class MainWindow(wx.Frame):
def __init__(self, parent, id, title = "Test GUI"):
wx.Frame.__init__(self, parent, wx.ID_ANY, title = "MyTitle", size=(1200,1000))
self.graphicsPanel = wx.Panel(self,-1,style=wx.CLIP_CHILDREN)
self.textPanel = wx.Panel(self)
self.buttonsPanel = wx.Panel(self)
self.graphicsPanel.figure = Figure()
self.graphicsPanel.canvas = FigureCanvas(self.graphicsPanel, -1, self.graphicsPanel.figure)
self.axeshandleA = self.graphicsPanel.figure.add_subplot(131, projection='3d',facecolor='#f3f3f3')
self.axeshandleB = self.graphicsPanel.figure.add_subplot(132, projection='3d',facecolor='#f3f3f3')
self.axeshandleC = self.graphicsPanel.figure.add_subplot(133, projection='3d',facecolor='#f3f3f3')
if __name__ == '__main__':
app = wx.App(False)
app.frame = MainWindow(None, wx.ID_ANY)
app.frame.Show()
app.MainLoop()
我认为我需要从三个面板开始,我不得不垂直对齐。
我想在中间面板中我需要添加三个额外的面板并水平对齐
我的大脑正在思考如何在HTML和CSS中构建div框。
我的第一个问题是我无法弄清楚如何让面板填充a)填充父级和b)垂直对齐。
其次,我在Spyder工作。为什么每次打电话给gui后都要启动新的控制台?如果我没有,那么我就会收到错误
必须首先创建wx.App对象!
我真的很感激任何帮助,因为我被卡住了!非常感谢
我正在运行wxPython 4.0.0rc1.dev3617 + 346e3b7和Python 3.5.4
答案 0 :(得分:0)
经过大量的工作和预防后,我现在有了这个GUI:
按钮仍然比我想要的宽,但我无法弄清楚如何使它们变窄。
我使用的代码是
import wx
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
from mpl_toolkits.mplot3d import Axes3D
class MainWindow(wx.Frame):
def __init__(self, parent, id, title = "Test GUI"):
wx.Frame.__init__(self, parent, wx.ID_ANY, title = "MyTitle", size=(1200,1000))
self.graphicsPanel = wx.Panel(self,-1,style=wx.CLIP_CHILDREN)
self.graphicsPanel.SetBackgroundColour('#3aafbb')
self.textPanel = wx.Panel(self)
self.textPanel.SetBackgroundColour('#ffaf33')
self.buttonsPanel = wx.Panel(self)
self.buttonsPanel.SetBackgroundColour('#489e3e')
self.graphicsPanel.figure = Figure()
self.graphicsPanel.canvas = FigureCanvas(self.graphicsPanel, 1, self.graphicsPanel.figure)
main_sizer = wx.BoxSizer(wx.VERTICAL)
main_sizer.Add(self.graphicsPanel, 3, wx.EXPAND, border = 20)
main_sizer.Add(self.textPanel, 6, wx.EXPAND, border = 20)
main_sizer.Add(self.buttonsPanel, 1, wx.EXPAND, border = 20)
self.SetSizer(main_sizer)
self.Maximize(True)
self.axeshandleA = self.graphicsPanel.figure.add_subplot(131, projection='3d',facecolor='#f3f3f3')
self.axeshandleB = self.graphicsPanel.figure.add_subplot(132, projection='3d',facecolor='#f3f3f3')
self.axeshandleC = self.graphicsPanel.figure.add_subplot(133, projection='3d',facecolor='#f3f3f3')
self.graphicsPanel_sizer = wx.BoxSizer()
self.graphicsPanel_sizer.Add(self.graphicsPanel.canvas, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=10)
self.graphicsPanel.SetSizerAndFit(self.graphicsPanel_sizer)
self.textPanelR = wx.Panel(self.textPanel)
self.textPanelR.SetBackgroundColour('#f2c4f5')
self.textPanelA = wx.Panel(self.textPanel)
self.textPanelA.SetBackgroundColour('#86478a')
self.textPanelC = wx.Panel(self.textPanel)
self.textPanelC.SetBackgroundColour('#e11fee')
self.textPanel_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.textPanel_sizer.Add(self.textPanelR, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=20)
self.textPanel_sizer.Add(self.textPanelA, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=20)
self.textPanel_sizer.Add(self.textPanelC, 1, wx.EXPAND|wx.LEFT|wx.RIGHT|wx.TOP|wx.BOTTOM, border=20)
self.textPanel.SetSizerAndFit(self.textPanel_sizer)
self.backBtn = wx.Button(self.buttonsPanel,label='<<BACK',style=wx.BU_EXACTFIT, size=(50,30))
self.backBtn.Bind(wx.EVT_BUTTON, self.backBtnClicked)
self.exitBtn = wx.Button(self.buttonsPanel,label='EXIT',style=wx.BU_EXACTFIT, size=(50,30))
self.exitBtn.Bind(wx.EVT_BUTTON, self.exitBtnClicked)
self.nextBtn = wx.Button(self.buttonsPanel,label='NEXT>>',style=wx.BU_EXACTFIT, size=(50,30))
self.nextBtn.Bind(wx.EVT_BUTTON, self.nextBtnClicked)
self.buttonsPanel_sizer = wx.BoxSizer(wx.HORIZONTAL)
self.buttonsPanel_sizer.Add(self.backBtn, 1, wx.CENTER|wx.LEFT|wx.RIGHT, border=20)
self.buttonsPanel_sizer.Add(self.exitBtn, 1, wx.CENTER|wx.LEFT|wx.RIGHT, border=20)
self.buttonsPanel_sizer.Add(self.nextBtn, 1, wx.CENTER|wx.LEFT|wx.RIGHT, border=20)
self.buttonsPanel.SetSizer(self.buttonsPanel_sizer)
def backBtnClicked(self, event):
print("Back Button")
def nextBtnClicked(self, event):
print("Next Button")
def exitBtnClicked(self, event):
print("Exit Button")
if __name__ == '__main__':
app = wx.App(False)
app.frame = MainWindow(None, wx.ID_ANY)
app.frame.Show()
app.MainLoop()
我怀疑它是否尽可能高效,但它似乎主要按照我的意愿行事。我们将非常感激地收到任何进一步的建议或建议。