wxPython – wx.StatusBar 中的 SetStatusText()函数
在本文中,我们将学习与 wxPython 的 wx.StatuBar 类关联的 SetStatusText()函数。 SetStatusText()函数仅用于设置第 i 个字段的状态文本。
给定的文本将替换当前文本。状态栏的显示是立即更新的,所以调用这个函数后不需要再调用 wx.Window.Update 了。
Syntax: wx.StatuBar.SetStatusText(self, text, i=0)
Parameters:
Parameter | Input Type | Description |
---|---|---|
text | string | The text to be set. Use an empty string (“”) to clear the field. |
i | int | The field to set, starting from zero. |
代码示例:
import wx
class Example(wx.Frame):
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.statusbar = wx.StatusBar()
self.statusbar.Create(self, id = 1, name = "Status Bar")
self.SetStatusBar(self.statusbar)
self.SetSize((350, 250))
# SET TOTAL NUMBER OF FIELDS AND RESPECTIVE WIDTHS
self.statusbar.SetFieldsCount(3, [100, 80, 60])
# SET TEXT FOR ALL FIELDS
self.statusbar.SetStatusText("Field One", 0)
self.statusbar.SetStatusText("Field Two", 1)
self.statusbar.SetStatusText("Field Three", 2)
self.SetTitle('New Frame Title')
self.Centre()
print(self.statusbar.GetMinHeight())
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口: