在本文中,我們將學習與wxPython的wx.StatusBar類關聯的GetStatusText()函數。 GetStatusText()函數是wx.StatusBar中最有用的方法之一,因為此函數返回與狀態欄字段關聯的字符串。
隻需一個參數即可檢索狀態字段的編號(從零開始)。
用法: wx.StatusBar.GetStatusText(self, i=0)
參數:
參數 | 輸入類型 | 描述 |
---|---|---|
i | int | 要檢索的狀態字段的編號,從零開始。 |
返回值:狀態字段字符串(如果該字段有效),否則為空字符串。
返回類型:串
代碼示例:
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
輸出窗口:
相關用法
- wxPython wx.MenuItem SetMenu()用法及代碼示例
- wxPython wx.MenuBar Attach()用法及代碼示例
- wxPython wx.MenuItem SetSubMenu()用法及代碼示例
- wxPython wx.MenuItem SetTextColour()用法及代碼示例
- wxPython wx.MenuItem SetBackgroundColour()用法及代碼示例
- wxPython wx.MenuBar Detach()用法及代碼示例
- wxPython wx.StatusBar GetClassDefaultAttributes()用法及代碼示例
- wxPython wx.StatusBar GetBorders()用法及代碼示例
- wxPython wx.MenuBar GetMenus()用法及代碼示例
- wxPython wx.MenuBar Insert()用法及代碼示例
注:本文由純淨天空篩選整理自RahulSabharwal大神的英文原創作品 wxPython – GetStatusText() function in wx.StatusBar。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。