我尝试使用wx.SplitterWindow
将主窗口拆分为三个部分:一个顶部窗口和两个底部窗口(底部窗口左下角和右下角)。
修改
这是我拥有的和我所经历的:
from __future__ import print_function
from numpy import arange, sin, pi
import matplotlib
import matplotlib.pyplot as plt
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure
import wxmplot
import wx
import os
class topPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
#self.SetBackgroundColour("red")
class bottomLeft(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
def plotWaves(self,parent):
self.figureWave = Figure()
self.axes = self.figureWave.add_subplot(111,aspect='equal')
self.canvas = FigureCanvas(self, -1, self.figureWave)
t = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
s = [0.0, 1.0, 0.0, 1.0, 0.0, 2.0, 1.0, 2.0, 1.0, 0.0]
self.axes.plot(t, s)
self.sizerWave = wx.BoxSizer(wx.HORIZONTAL)
self.sizerWave.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizerWave)
self.Fit()
########################################################################
class bottomRight(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
def plotMAW(self,parent):
self.figureMAW = Figure()
self.axes = self.figureMAW.add_subplot(111,aspect='equal')
self.canvas = FigureCanvas(self, -1, self.figureMAW)
#self.axes.plot(self.waves)
t = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
s = [0.0, 1.0, 0.0, 1.0, 0.0, 2.0, 1.0, 2.0, 1.0, 0.0]
self.axes.plot(t, s)
self.sizerMAW = wx.BoxSizer(wx.HORIZONTAL)
self.sizerMAW.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizerMAW)
self.Fit()
########################################################################
### SETUP GUI HERE
class myGUI(wx.Frame):
def __init__(self):
self.main = wx.Frame.__init__(self, None, wx.ID_ANY, "myGUI", size=(850,500))
# DEFINE A SPLIT WINDOW FOR PLOTTING
self.splitWin = wx.SplitterWindow(self)
topP = topPanel(self)
bottomPLeft = bottomLeft(self.splitWin)
bottomPRight = bottomRight(self.splitWin)
# SPLIT THE WINDOW
self.splitWin.SplitVertically(bottomPLeft, bottomPRight)
self.splitWin.SetMinimumPaneSize(350)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(topP, 1, wx.EXPAND)
sizer.Add(self.splitWin, 1, wx.EXPAND)
self.SetSizer(sizer)
self.control = p = wx.Panel(self, 1, style=wx.TE_MULTILINE)
# SETUP CONFIG WINDOW
self.result = wx.StaticText(p, label="")
self.result.SetForegroundColour(wx.RED)
self.lblname = wx.StaticText(self, label="Config File:")
self.editname = wx.TextCtrl(self, size=(140, -1))
# Set sizer for the panel content
self.sizer = wx.GridBagSizer(5, 5)
self.sizer.Add(self.lblname, (1, 2))
self.sizer.Add(self.editname, (1, 3))
# SETUP RUN MENU
runMenu = wx.Menu() # create a menu for running DAQ
runConfig = runMenu.Append(wx.ID_ANY, "&Configure", "Load configuration file")
menuBar = wx.MenuBar()
menuBar.Append(runMenu, "&Run")
self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.
self.Bind(wx.EVT_MENU, self.onConfigure, runConfig)
self.Show(1)
self.aboutme = wx.MessageDialog( self, " A sample editor \n"
" in wxPython","About Sample Editor", wx.OK)
self.doiexit = wx.MessageDialog( self, " Exit - R U Sure? \n",
"GOING away ...", wx.YES_NO)
self.dirname = ''
def onConfigure(self,e):
# Load specific configuration file for system being used
openFileDialog = wx.FileDialog(self, "Open", "", "",
"Python files (*.py)|*.py",
wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_OK:
self.filename=openFileDialog.GetFilename()
self.dirname=openFileDialog.GetDirectory()
filehandle=open(os.path.join(self.dirname, self.filename),'r')
self.configName = self.filename[:-3]
filehandle.close()
lP = bottomLeft(self)
lP.plotWaves(self)
rP = bottomRight(self)
rP.plotMAW(self)
self.editname.AppendText(self.configName)
openFileDialog.Destroy()
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = myGUI()
frame.Show()
app.MainLoop()
这是我的GUI的完整示例,如果您运行配置菜单并加载任何文件(这不重要,因为这只是运行def plotWaves和def plotMAW函数),您将看到这些图超越GUI。如果您注释掉def plotWaves(self,parent):
行和def plotMAW(self,parent):
行,则图表会显示在正确的位置。如果您注释掉定义行,则第一个图像显示结果。如果你不注释它们,第二张图片会显示结果。
答案 0 :(得分:0)
可以这样吗?
import wx
class MainGUI(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent=None, size=(750,500))
self.Centre()
topPanel = TopPanel(self)
hLeftPanel = LeftPanel(self)
hRightPanel = RightPanel(self)
hBoxSizer = wx.BoxSizer(wx.HORIZONTAL)
hBoxSizer.Add(hLeftPanel, 1, wx.EXPAND)
hBoxSizer.Add(hRightPanel, 1, wx.EXPAND)
vBoxSizer = wx.BoxSizer(wx.VERTICAL)
vBoxSizer.Add(topPanel, 1, wx.EXPAND)
vBoxSizer.Add(hBoxSizer, 1, wx.EXPAND)
self.SetSizer(vBoxSizer)
class TopPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetBackgroundColour("red")
class LeftPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetBackgroundColour("blue")
class RightPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.SetBackgroundColour("green")
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MainGUI()
frame.Show()
app.MainLoop()
我希望我有所帮助!
答案 1 :(得分:0)
您不能定义2个面板来构成显示屏的底部 这是你在找什么:
import wx
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
class topPanel(wx.Panel):
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
Text=wx.StaticText(self, -1, ("Top Panel"))
class bottomRight(wx.Panel):
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
Text=wx.StaticText(self, -1, ("Bottom Right"))
class bottomLeft(wx.Panel):
# PANEL FOR PLOTTING DATA AS IT COMES IN
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
Text = wx.StaticText(self,-1,"Bottom Left")
self.figure = Figure()
self.axes = self.figure.add_subplot(111,aspect='equal')
self.canvas = FigureCanvas(self, -1, self.figure)
t = [ 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]
s = [0.0, 1.0, 0.0, 1.0, 0.0, 2.0, 1.0, 2.0, 1.0, 0.0]
self.axes.plot(t, s)
self.sizer = wx.BoxSizer(wx.HORIZONTAL)
self.sizer.Add(Text, 0,0,0,0)
self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
self.SetSizer(self.sizer)
self.Fit()
class myGUI(wx.Frame):
def __init__(self):
self.main = wx.Frame.__init__(self, None, wx.ID_ANY, "myGUI", size=(750,500))
# DEFINE A SPLIT WINDOW
self.splitWin = wx.SplitterWindow(self)
topP = topPanel(self)
bottomPLeft = bottomLeft(self.splitWin)
bottomPRight = bottomRight(self.splitWin)
# SPLIT THE WINDOW
self.splitWin.SplitVertically(bottomPLeft, bottomPRight)
self.splitWin.SetMinimumPaneSize(350)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(topP, 1, wx.EXPAND)
sizer.Add(self.splitWin, 1, wx.EXPAND)
self.SetSizer(sizer)
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = myGUI()
frame.Show()
app.MainLoop()