Open In App

wxPython – SetStatusWidths() function in wx.StatusBar

Improve
Improve
Like Article
Like
Save
Share
Report

In this article we are going to learn about SetStatusWidths() function associated with wx.StatuBar class of wxPython. SetStatusWidths() function sets the widths of the fields in the status line.

There are two types of fields: fixed widths and variable-width fields. For the fixed-width fields you should specify their (constant) width in pixels. For the variable width fields, specify a negative number which indicates how the field should expand: the space left for all variable width fields is divided between them according to the absolute value of this number. A variable-width field with width of -2 gets twice as much of it as a field with width -1 and so on.

Syntax: wx.StatuBar.SetStatusWidths(self, widths)

Parameters:

Parameter Input Type Description
widths list of ints The text to be set. Use an empty string (“”) to clear the field.
i int Contains an array of n integers, each of which is either an absolute status field width in pixels if positive or indicates a variable width field if negative. The special value None means that all fields should get the same width.

Code Example:




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))
  
        self.statusbar.SetFieldsCount(3)
  
        # SET WIDTHS FOR CORRESPONDING FIELD
        self.statusbar.SetStatusWidths([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()


Output Window:



Last Updated : 15 Jun, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads