Prev

Up

Next

wxGlade tutorial - Status bar

(Contributed by Chris Lale, chrislale AT users DOT berlios DOT de)

Table of Contents:

Create the application in wxglade

Run wxglade. Open the events and buttons project event-glade.wxg that you created in "Events and buttons" (WxGladeEventsButtons). The project consists of a frame containing one button. Set the title to "statusbar-glade" and save it as statusbar-glade.py. In the main (toolbox) window

The Tree shows that the application contains one frame, a sizer and a button.

About the wx.StatusBar class

A status bar is a narrow window that can be placed along the bottom of a frame to give small amounts of status information. It can contain one or more fields, one or more of which can be variable length according to the size of the window.

The constructor is __init__(self, parent, id, pos, size, style, name), but you only need to specify the first two: parent, and id.

Look for wx.StatusBar's methods in

and

Add a status bar to the frame

This creates frame_1_statusbar. In frame_1_statusbar's Properties window, accept the defaults:

The status bar instance method is added to MyFrame's __init()__ method:

   1         self.frame_1_statusbar = self.CreateStatusBar(1, 0)

The status bar size (width) and text are set in the __set_properties() method

   1         self.frame_1_statusbar.SetStatusWidths([-1])
   2         # statusbar fields
   3         frame_1_statusbar_fields = ["frame_1_statusbar"]
   4         for i in range(len(frame_1_statusbar_fields)):
   5             self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)
   6         # end wxGlade

Check the result:

Create an event handler to modify the status bar

Set Output path to /path/to/your/project/staturbar-glade.py, generate the code and edit statusbar-glade.py.

Modify the existing event handler for button_1. Change

   1     def OnBtn1(self, event): # wxGlade: MyFrame.<event_handler>
   2         self.button_1.SetLabel("Ouch!")
   3         event.Skip()

to

   1     def OnBtn1(self, event): # wxGlade: MyFrame.<event_handler>
   2         self.frame_1_statusbar.SetStatusText("Ouch!")
   3         event.Skip()

Save statusbar-glade.py and run it.

Appendix: The complete code

   1 #!/usr/bin/env python
   2 # -*- coding: ISO-8859-1 -*-
   3 # generated by wxGlade 0.4.1 on Thu Mar 30 13:53:04 2006
   4 
   5 import wx
   6 
   7 class MyFrame(wx.Frame):
   8     def __init__(self, *args, **kwds):
   9         # begin wxGlade: MyFrame.__init__
  10         kwds["style"] = wx.DEFAULT_FRAME_STYLE
  11         wx.Frame.__init__(self, *args, **kwds)
  12         self.button_1 = wx.Button(self, wx.ID_OK, "")
  13         self.frame_1_statusbar = self.CreateStatusBar(1, 0)
  14 
  15         self.__set_properties()
  16         self.__do_layout()
  17 
  18         self.Bind(wx.EVT_BUTTON, self.OnBtn1, id=wx.ID_OK)
  19         # end wxGlade
  20 
  21     def __set_properties(self):
  22         # begin wxGlade: MyFrame.__set_properties
  23         self.SetTitle("statusbar-glade")
  24         self.SetSize((350, 250))
  25         self.frame_1_statusbar.SetStatusWidths([-1])
  26         # statusbar fields
  27         frame_1_statusbar_fields = ["frame_1_statusbar"]
  28         for i in range(len(frame_1_statusbar_fields)):
  29             self.frame_1_statusbar.SetStatusText(frame_1_statusbar_fields[i], i)
  30         # end wxGlade
  31 
  32     def __do_layout(self):
  33         # begin wxGlade: MyFrame.__do_layout
  34         sizer_1 = wx.BoxSizer(wx.VERTICAL)
  35         sizer_1.Add(self.button_1, 0, wx.ADJUST_MINSIZE, 0)
  36         self.SetAutoLayout(True)
  37         self.SetSizer(sizer_1)
  38         self.Layout()
  39         # end wxGlade
  40 
  41     def OnBtn1(self, event): # wxGlade: MyFrame.<event_handler>
  42         self.frame_1_statusbar.SetStatusText("Ouch!")
  43         event.Skip()
  44 
  45 # end of class MyFrame
  46 
  47 
  48 class MyApp(wx.App):
  49     def OnInit(self):
  50         wx.InitAllImageHandlers()
  51         frame_1 = MyFrame(None, -1, "")
  52         self.SetTopWindow(frame_1)
  53         frame_1.Show()
  54         return 1
  55 
  56 # end of class MyApp
  57 
  58 if __name__ == "__main__":
  59     app = MyApp(0)
  60     app.MainLoop()

WxGladeStatusbar (last edited 2013-10-17 20:44:51 by static-66-212-195-213)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.