Monday, September 10, 2012

wxPython STATIC TEXT





REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create wxPython static text.

I.  wxPYTHON STATIC TEXT

Static text is text that appears on the panel. There are many ways to customize the static text.  For example, you can customize the static text by adding foreground and background colors. You can also align the static text; i.e., center the text.

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 Static Text', size=(800,400))
                panel=wx.Panel(self)

Creates plain static text
# Four parameters
# 1. parent is panel
# 2. ID Number is -1
# 3. The text you want to be static text
# 4. The position of the static text x, y coordinates
#     x = 15 across, y = 20 down from top left corner of the panel  
                wx.StaticText(panel, -1, 'Happy days are here again!',(15,20))

Creates custom static text with foreground and background colors
# Foreground is text, background is hi-light
# Four parameters
# 1. parent is panel
# 2. ID Number is -1
# 3. The text you want to be static text
# 4. The position of the static text x, y coordinates
#     x = 15 across, y = 40 down from top left corner of the panel  
                custom=wx.StaticText(panel, -1, 'Let the good times roll!',(15,40))
                custom.SetForegroundColour('white')
                custom.SetBackgroundColour('blue')

Creates custom aligned static text with foreground and background colors
# Foreground is text, background is hi-light
# Six parameters
# 1. parent is panel
# 2. ID Number is -1
# 3. The text you want to be static text
# 4. The position of the static text x, y coordinates
#     x = 15 across, y = 60 down from top left corner of the panel
# 5. Width of the background banner, and height of background banner
# 6. Center alignment  
                custom=wx.StaticText(panel, -1, 'Let the good times roll!',(15,60), (800, -1), wx.ALIGN_CENTER)
                custom.SetForegroundColour('white')
                custom.SetBackgroundColour('blue')

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 brightStaticText.py to the same path which your computer used to download Python 2.7.3. For example, I saved my bright StaticText.py  file  to my Python27 folder using the following path:

C:\Python27\bright StaticText.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "Bright List" in the top left corner will open.  The comments which start with  a hash, #, sign explain how this wxPython program works. 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 wxPython static text.

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