现在解决了上一个问题,我遇到了一个新问题:但现在我无法更改statusText项的文本。
#Parent panel
pnl = wx.Panel(self)
pnl.SetBackgroundColour('#4f5049')
vbox = wx.BoxSizer(wx.VERTICAL)
midPan = wx.Panel(pnl)
midPan.SetBackgroundColour('#ededed')
vbox.Add(midPan,wx.ID_ANY, wx.EXPAND |wx.ALL, 20)
sizer = wx.GridBagSizer(10,5)
#sizer.
midPanelsT1=wx.StaticText(midPan,label='-- Checklist --')
sizer.Add(midPanelsT1, pos=(0,1),flag=wx.ALL,border=2)
当我按如下方式添加定义时:
def onStart(self,e):
self.sb.SetStatusText('Counting processes',1)
count = 0
for process in c.Win32_Process():
count +=1
self.sb.SetStatusText('Found '+str(count)+' running processes',1)
self.midPanelsT1.SetLabel(str(count))
标签没有变化,而(str(count))大约为300,这在sb中显示。如何返回StatusText项目?
这可能取决于您如何定义状态栏,我假设这是您所指的,因为您没有在代码中声明或显示它。
import wx
class MyFrame(wx.Frame):
def __init__(self, parent, id=wx.ID_ANY, title="", size=(360,100)):
super(MyFrame, self).__init__(parent, id, title, size)
pnl = wx.Panel(self)
pnl.SetBackgroundColour('#4f5049')
btn = wx.Button(pnl, wx.ID_ANY, 'Start')
vbox = wx.BoxSizer(wx.VERTICAL)
midPan = wx.Panel(pnl)
midPan.SetBackgroundColour('green')
self.sb = wx.StatusBar(self)
self.sb.SetFieldsCount(2)
self.SetStatusBar(self.sb)
self.sb.SetStatusText('Counting processes',1)
vbox.Add(midPan,wx.ID_ANY, wx.EXPAND |wx.ALL, 20)
vbox.Add(btn,wx.ID_ANY, wx.ALL, 5)
sizer = wx.GridBagSizer(10,5)
st1=wx.StaticText(midPan,label='Black on green')
st2=wx.StaticText(midPan,label='White on green')
st2.SetForegroundColour('white')
st3=wx.StaticText(midPan)
st3.SetLabelMarkup("<span foreground='black' background='red'>Black on red</span>")
st4=wx.StaticText(midPan)
st4.SetLabelMarkup("<span foreground='white' background='red'>White on red</span>")
sizer.Add(st1, pos=(1,1),flag=wx.ALL,border=5)
sizer.Add(st2, pos=(2,2),flag=wx.ALL,border=5)
sizer.Add(st3, pos=(3,3),flag=wx.ALL,border=5)
sizer.Add(st4, pos=(4,1),flag=wx.ALL,border=5)
midPan.SetSizer(sizer)
pnl.SetSizer(vbox)
self.Bind(wx.EVT_BUTTON, self.onStart, btn)
self.Show()
def onStart(self,event):
toggle = self.sb.GetStatusText(1)
if toggle == 'Started....':
self.sb.SetStatusText('Stopped....',1)
else:
self.sb.SetStatusText('Started....',1)
if __name__ == "__main__":
app = wx.App()
frame = MyFrame(None,title="The Main Frame")
app.MainLoop()