wxPython – wx.StatusBar 中的 GetStatusText()函数
在本文中,我们将学习与 wxPython 的 wx.StatusBar 类关联的 GetStatusText()函数。 GetStatusText()函数是 wx.StatusBar 中最有用的方法之一,因为该函数返回与状态栏字段关联的字符串。
它只需要一个参数来检索状态字段的编号,从零开始。
Syntax: wx.StatusBar.GetStatusText(self, i=0)
Parameters:
Parameter | Input Type | Description |
---|---|---|
i | int | The number of the status field to retrieve, starting from zero. |
Returns: The status field string if the field is valid, otherwise the empty string.
Return Type: string
代码示例:
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, style = wx.STB_DEFAULT_STYLE,
name = "Status Bar")
self.SetStatusBar(self.statusbar)
self.SetSize((350, 250))
self.statusbar.SetFieldsCount(2)
self.statusbar.SetStatusWidths([150, 150])
self.statusbar.SetStatusText("This is first field", 0)
self.statusbar.SetStatusText("This is second field", 1)
self.statusbar.SetStatusStyles(styles =[wx.SB_RAISED, wx.SB_SUNKEN])
# PRINT STATUS TEXT OF TWO FIELDS
print("First Field Text: "+self.statusbar.GetStatusText(0))
print("Second Field Text: "+self.statusbar.GetStatusText(1))
self.SetTitle('New Frame Title')
self.Centre()
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
控制台输出:
First Field Text: This is first field
Second Field Text: This is second field
输出窗口: