我设法让工具栏显示,但工具栏上的按钮没有响应。我听说工具栏只能使用boxsizer工具,所以试图通过在gridbag sizer中放置一个boxsizer将其集成到代码中。这没用。我已将matplotlib和wxpython更新到今天的最新版本。请查看我的代码,因为我认为我可能会遗漏一些明显的内容。
class Example(wx.Frame):
def __init__(self, parent, title):
super(Example, self).__init__(parent, title=title,size=(628, 708))
self.InitUI()
self.Centre()
self.Show()
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
font.SetPointSize(9)
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
sizer = wx.GridBagSizer(8, 4)
title = wx.StaticText(panel, label="WORK FUNCTION CALCULATOR", style = wx.ALIGN_CENTRE )
sizer.Add(title, pos=(0, 1),span = (1,5), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.RIGHT|wx.BOTTOM, border=20)
tp = wx.StaticText(panel, label="File To Process", style = wx.ALIGN_CENTRE )
sizer.Add(tp, pos=(1, 0),span = (1,1), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.LEFT, border=10)
od1 = wx.StaticText(panel, label="Work Function", style = wx.ALIGN_CENTRE )
sizer.Add(od1, pos=(1, 4),span = (1,1), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.LEFT, border=10)
od2 = wx.StaticText(panel, label="Ratio of Counts", style = wx.ALIGN_CENTRE )
sizer.Add(od2, pos=(2, 0),span = (1,1), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.LEFT, border=10)
od3 = wx.StaticText(panel, label="Applied Bias", style = wx.ALIGN_CENTRE )
sizer.Add(od3, pos=(3, 0),span = (1,1), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.LEFT, border=50)
od4 = wx.StaticText(panel, label="Method of Calculation", style = wx.ALIGN_CENTRE )
sizer.Add(od4, pos=(1, 2),span = (1,1), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.LEFT, border=10)
self.listbox1 = wx.ListBox(panel,-1,size=(110, 22))
self.listbox1.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)
dt = FileDrop(self.listbox1)
self.listbox1.SetDropTarget(dt)
sizer.Add(self.listbox1, pos=(1, 1), flag=wx.EXPAND|wx.ALIGN_CENTRE, border=10)
self.listbox2 = wx.ListBox(panel,-1,size=(150, 25))
sizer.Add(self.listbox2, pos=(2, 4),flag=wx.ALIGN_CENTRE, border=10)
self.ratioTC = wx.TextCtrl(panel,wx.TE_PASSWORD)
sizer.Add(self.ratioTC, pos = (2,1), flag=wx.EXPAND|wx.ALIGN_CENTRE, border=10)
self.biasTC = wx.TextCtrl(panel,wx.TE_PASSWORD)
sizer.Add(self.biasTC, pos = (3,1), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.BOTTOM, border=10)
buttonProcess = wx.Button(panel, label="Process -->")
buttonProcess.Bind(wx.EVT_BUTTON, self.OnProcess)
sizer.Add(buttonProcess, pos=(2, 3), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.LEFT, border=10)
methods = ['1', '2', '3', '4']
self.cb = wx.ComboBox(panel, pos=(50, 30), choices=methods,size = (100,20), style=wx.CB_READONLY)
sizer.Add(self.cb, pos=(2, 2), flag=wx.EXPAND|wx.ALIGN_CENTRE|wx.LEFT, border=10)
self.figure = Figure()
self.axes = self.figure.add_subplot(111)
self.canvas = FigureCanvas(self, -1, self.figure)
vbox.Add(self.canvas,1, flag=wx.EXPAND|wx.ALIGN_CENTRE, border=5)
self.chart_toolbar = NavigationToolbar2Wx(self.canvas)
tw,th = self.chart_toolbar.GetSizeTuple()
fw,fh = self.canvas.GetSizeTuple()
self.chart_toolbar.SetSize(wx.Size(fw, th))
self.chart_toolbar.Realize()
vbox.Add(self.chart_toolbar,0,flag=wx.ALIGN_CENTRE|wx.BOTTOM, border = 5)
sizer.Add(vbox, pos=(4,0), span=(4,5),flag=wx.ALIGN_CENTRE|wx.BOTTOM, border = 5)
panel.SetSizerAndFit(sizer)
self.chart_toolbar.update()
self.canvas.Update()
self.canvas.Refresh()
self.Update()
此代码块中提到的所有其他功能都不会影响工具栏。