In this article we are going to learn about SetFieldsCount() function associated with wx.StatusBar class of wxPython. SetFieldsCount() function is simply used to set the number of fields, and optionally the field widths. It takes two parameters number of Field to be set and list of widths for the corresponding fields.
Syntax:
wx.StatusBar.SetFieldsCount(self, number=1, widths=None)Parameters:
Parameter Input Type Description number int The number of fields. If this is greater than the previous number, then new fields with empty strings will be added to the status bar. widths list of ints An array of n integers interpreted in the same way as in SetStatusWidths.
Code Example:
Python3
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 )) # 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() def main(): app = wx.App() ex = Example( None ) ex.Show() app.MainLoop() if __name__ = = '__main__' : main() |
Output Window: