Wednesday, September 12, 2012

wxPYTHON CHOICE LIST DIALOG





REVISED:  REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create a wxPython choice list dialog box.

I.  wxPYTHON CHOICE LIST DIALOG BOX

When the program starts the choice list dialog box is displayed. When the user selects a color and clicks OK the "choice list dialog box" is destroyed and the users color selection is printed on the open Python Shell window. When the user clicks Cancel, the "choice list dialog box" is destroyed and the Python Shell window remains open.

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.  Use four spaces, columns, for each indent.

import wx

if __name__=='__main__':

# Creates application object named app
        app=wx.PySimpleApp()

# Python list named colorList, first color is 0, second color is 1; etc.
        colorList=['blue', 'green', 'orange', 'purple', 'red',   'violet', 'yellow']

# Creates list dialog box object named color
# Four parameters:
# 1. Parent name is None
# 2. User prompt, is "What is your lucky color?"
# 3. List dialog box title, is "LUCKY COLORS"
# 4. Python list is named colorList
        color=wx.SingleChoiceDialog(None, "What is your lucky color?", "LUCKY COLORS", colorList)

# If OK is clicked, uses string variable %s to print their lucky color on Python Shell window
        if color.ShowModal()==wx.ID_OK:
                print "Your lucky color is %s\n" % color.GetStringSelection()

# Destroys list dialog box object named color
        color.Destroy()

From the "New Window", do a "File Save As" and save the above Python program, using the file name brightListDialog.py to the same path which your computer used to download Python 2.7.3. For example, I saved my brightListDialog.py  file  to my Python27 folder using the following path:

C:\Python27\brightListDialog.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "PLAIN FRAME WINDOW" 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 a wxPython choice list dialog box.

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"




Tuesday, September 11, 2012

wxPYTHON LIST BOX





REVISED:  REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create a wxPython list box.

I.  wxPYTHON LIST BOX

The PLAIN FRAME WINDOW opens with the list box displayed.

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,'PLAIN FRAME WINDOW', size=(600,400))
                panel=wx.Panel(self)

# Python list named petList, first pet is 0, second pet is 1; etc.
                petList=['Baby Python Snake', 'Baby Dragon', 'Baby Elephant', 'Puppy', 'Kitten', 'Baby Panda Bear', 'Tiger Cub']

# Creates list box object named yard
# Six parameters:
# 1. Parent name is panel
# 2. ID is -1
# 3. List box position on the frame, 20 across, and 20 down from top left corner of frame
# 4. List box size, width and height in pixels
# 5. Name of list is petList
# 6. List box style is wx.LB_SINGLE so only one pet can be selected
                yard=wx.ListBox(panel, -1, (20,20), (200,60), petList, wx.LB_SINGLE)

# Creates list box default selection 
# One parameter:
# 1. Default selection when program starts is pet 4, list count starts from zero
                yard.SetSelection(4)

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

C:\Python27\brightListBox.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "PLAIN FRAME WINDOW" 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 a wxPython list box.

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"




wxPYTHON CHECK BOX





REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create a wxPython check box.

I.  wxPYTHON CHECK BOX

The PLAIN FRAME WINDOW opens with the check box displayed.

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,'PLAIN FRAME WINDOW', size=(600,400))
                panel=wx.Panel(self)

# Creates check box
# Five parameters:
# 1. Parent name is panel
# 2. ID is -1
# 3. Label for check box
# 4. Check box position on the frame 10 across and 15 down from top left corner of frame
# 5. Check box width of 100 pixels, and default height of -1
                wx.CheckBox(panel, -1, "Cat", (10,15), (100,-1))

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

C:\Python27\brightCheckBox.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "PLAIN FRAME WINDOW" 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 a wxPython check box.

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"




wxPYTHON SPINNER





REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create a wxPython spinner.

I.  wxPYTHON SPINNER

The PLAIN FRAME WINDOW opens with the spinner displayed in the top left corner of the frame.

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,'PLAIN FRAME WINDOW', size=(600,400))
                panel=wx.Panel(self)

# Creates spinner object named spinner
# Five parameters:
# 1. Parent name is panel
# 2. ID is -1
# 3. Empty string ""
# 4. Spinner position on the frame 10 across and 20 down from top left corner of frame
# 5. Spinner width of 100 pixels, and default height of -1
                spinner=wx.SpinCtrl(panel, -1, "", (10,20), (100,-1))

# Sets spinner min and max range as a tuple
# Two parameters:
# 1. Min value of 1
# 2. Max value of 100
                spinner.SetRange(1,100)

# Set spinner default value
# One parameter:
# 1. Value in spinner when program starts
                spinner.SetValue(50)

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

C:\Python27\brightSpinner.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "PLAIN FRAME WINDOW" 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 a wxPython spinner.

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"




wxPYTHON SLIDERS





REVISED: Sunday, March 3, 2013



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

I.  wxPYTHON SLIDER

The PLAIN FRAME WINDOW opens with the slider displayed in the top left corner of the frame.

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,'PLAIN FRAME WINDOW', size=(600,400))
                panel=wx.Panel(self)

# Creates slider object named slider
# parameters:
# 1. Parent name is panel
# 2. ID is -1
# 3. Default center of slide is 250
# 4. Start of slide is 1
# 5. Maximum or end of slider is 500
# 6. Position of slide, on frame, 10 pixels across and 20 pixels down from top left corner of frame
# 7. Size is 550 wide and -1 height
# 8. Two styles, wx.SL_AUTOTICKS and wx.SL_LABELS
                slider=wx.Slider(panel, -1, 50, 1, 100, pos=(10,10), size=(250,-1), style=wx.SL_AUTOTICKS | wx.SL_LABELS)

# Set ticker frequency
# Two parameters:
# 1. How far apart ticks are placed
# 2. Unit of measure is 1
                slider.SetTickFreq(5,1)

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

C:\Python27\brightSlider.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "PLAIN FRAME WINDOW" 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 sliders.

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"




wxPYTHON CUSTOM BITMAP BUTTONS





REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create wxPython custom bitmap buttons.

I.  wxPYTHON BITMAP BUTTON

The PLAIN FRAME WINDOW opens with the Yoda.bmp file displayed in the top left corner of the frame.

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,'PLAIN FRAME WINDOW', size=(600,400))
                panel=wx.Panel(self)

# Stores bitmap in object named pic
# Two parameters:
# 1. File name Yoda.bmp should be in same directory as Python
# 2. wx.BITMAP_TYPE_BMP
                pic=wx.Image("Yoda.bmp", wx.BITMAP_TYPE_BMP).ConvertToBitmap()

# Creates bitmap button
# Four parameters:
# 1. Parent name is panel
# 2. ID is -1
# 3. Button name is pic
# 4. Position is 1 across and 1 down from top left corner of PLAIN FRAME WINDOW 
                self.button=wx.BitmapButton(panel, -1, pic, pos=(1,1))
# Binds an event to the button
# Three parameters:
# 1. wx.EVT_BUTTON event is clicking the button
# 2. Calls self.ohOh method
# 3. self.button
                self.Bind(wx.EVT_BUTTON, self.ohOh, self.button)

# Button default
                self.button.SetDefault()

# Executes ohOh method when button is clicked
# Closes the button
        def ohOh(self, event):
                self.Destroy()

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

C:\Python27\brightBitmapButton.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "PLAIN FRAME WINDOW" 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 custom bitmap buttons.

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"




wxPYTHON SIMPLE TEXT PROGRAM





REVISED: Sunday, March 3, 2013



In this tutorial, you will learn how to create a wxPython simple text program.

I.  wxPYTHON SIMPLE TEXT PROGRAM

A.  wxPYTHON "DIALOG BOX" FRAME

A dialog box, text box, is used to prompt the user for information. The  text box title, DIALOG BOX, is shown at the top left of the panel. The question the user is to respond to, is show under the text box title. The text box, where the user enters a response, is in the center on the panel. The bottom of the panel has two buttons: OK, and Cancel. If the user clicks Cancel, the user response is not assigned to a variable and the DIALOG BOX frame is closed. If the user clicks OK, the user response is assigned to a variable, and the DIALOG BOX frame is closed.

B.  wxPYTHON "FRAME WINDOW" FRAME

When the DIALOG BOX frame closes, the plain FRAME WINDOW opens with the user response displayed.

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,'PLAIN FRAME WINDOW', size=(600,400))
                panel=wx.Panel(self)

# Creates a dialog box object named box
# Four parameters:
# 1. Parent name is panel
# 2. User prompt, question
# 3. Dialog Box frame title
# 4. Dialog Box default text
                box=wx.TextEntryDialog(panel, 'What color is the White House?','DIALOG BOX FRAME','Enter a color.')

# Stores user response in variable answer, if user clicks OK
                answer=" "
                if box.ShowModal()==wx.ID_OK:
                        answer=box.GetValue()

# Writes user input to the PLAIN FRAME WINDOW
# Four parameters:
# 1. Parent name is panel
# 2. ID is -1
# 3. Variable is answer
# 4. Position is 15 across and 20 down from top left corner of PLAIN FRAME WINDOW 
                wx.StaticText(panel, -1, answer, (15,20))

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

C:\Python27\brightSimpleText.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "DIALOG BOX FRAME" 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 a wxPython simple text program.

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"