REVISED: Sunday, March 3, 2013
In this tutorial, you will learn how to create a status bar, a menu bar, and a menu.
I. wxPYTHON STATUS BAR AND MENU BAR
The wxPython GUI toolkit starts with a frame. Inside the frame is a panel. Inside the panel are the buttons that the user uses to run the wxPython code. The menu bar is placed horizontally across the top of the panel. Menus are placed from left to right inside the menu bar. The status bar is placed horizontally across the bottom of the panel. When you hover your cursor over a menu list option its description appears on the status bar.
II. wxPYTHON EXAMPLE PROGRAM
Start the Python 2.7.3 interpreter shell by "double left mouse clicking" the Python icon on your desktop. When the "Python Shell" window opens select "File", then select "New Window". In the "New Window" type the following code, which is an expansion of the class bright we worked with in the last tutorial. Use four spaces, columns, for each indent.
import wx
class bright(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Bright Menu', size=(800,400))
panel=wx.Panel(self)
# Creates a status bar object named status
status=self.CreateStatusBar()
# Creates a menu bar object named menubar
# Menubar holds two menus: File and Edit
menubar=wx.MenuBar()
# Creates a menu object named first for File menu
first=wx.Menu()
# Creates a menu object named second for Edit menu
second=wx.Menu()
# Creates File menu element New Window
first.Append(wx.NewId(),"New Window","This is a new window")
# Creates File menu element Open...
first.Append(wx.NewId(),"Open...","This will open a new window")
# Appends first to menubar and names it File
menubar.Append(first,"File")
# Appends second to menubar and names it Edit
menubar.Append(second,"Edit")
# Sets menubar on the screen
self.SetMenuBar(menubar)
if __name__=='__main__':
app=wx.PySimpleApp()
frame=bright(parent=None,id=-1)
frame.Show()
app.MainLoop()
From the "New Window", do a "File Save As" and save the above Python program, using the file name brightMenu.py to the same path which your computer used to download Python 2.7.3. For example, I saved my brightMenu.py
file to my Python27 folder using the following path:
C:\Python27\brightMenu.py
From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "Bright Menu" in the top left corner will open. The comments which start with a hash, #, sign explain how this wxPython program works. Also, notice some of the underscores are double underscores; e.g., __init__, __name__, and __main__ all have double underscores before and after them.
In this tutorial, you have learned how to create a status bar, a menu bar, and a menu.
Elcric Otto Circle
Elcric Otto Circle
-->
-->
-->
How to Link to My Home Page
It will appear on your website as:"Link to ELCRIC OTTO CIRCLE's Home Page"
No comments:
Post a Comment