Showing posts with label wxPython example program. Show all posts
Showing posts with label wxPython example program. Show all posts

Tuesday, September 11, 2012

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"




Monday, September 10, 2012

wxPYTHON TEXT BOX





REVISED: Sunday, March 3, 2013



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

I.  wxPYTHON TEXT BOX

A dialog box, text box, is used to get input from the user. The  text box title 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 frame is closed. If the user clicks OK the user response is assigned to a variable and the frame is closed.

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

# Creates a dialog box object named box
                box=wx.TextEntryDialog(panel, 'What color is the White House?','QUESTION','Green')

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

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

C:\Python27\brightTextBox.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "Bright Text Box" 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 text 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"




Sunday, September 9, 2012

wxPYTHON STATUS BAR AND MENU BAR





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



-->



-->



-->






 







How to Link to My Home Page

It will appear on your website as:
"Link to ELCRIC OTTO CIRCLE's Home Page"




CREATING wxPYTHON PANELS AND BUTTONS





REVISED: Sunday, March 3, 2013




In this tutorial, you will learn how to create panels and buttons inside the wxPython GUI frame.

I.  wxPYTHON PANELS AND BUTTONS

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.

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 created 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 Button', size=(800,400))
# Creates a panel object named panel
                panel=wx.Panel(self)
# Creates a button object named button
# Button label is Exit
# Button location inside the panel is in x, y coordinates
# x = 0 pixels from left hand side of the panel
# y = 0 pixels down from the top of the panel
# The x, y coordinates are to the top left corner of the button
# Button size is width, height; 50 wide, 50 tall
                button=wx.Button(panel,label="Exit",pos=(0,0),size=(50,50))

# Binds two events to the button
# First event is clicking button to close the button
# Clicking button calls method closebutton
                self.Bind(wx.EVT_BUTTON, self.closebutton, button)
# Second event is clicking X to close the window
# Clicking X calls method closewindow
                self.Bind(wx.EVT_CLOSE, self.closewindow)

# Defines method closebutton
        def closebutton(self,event):
                self.Close(True)

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

C:\Python27\brightButton.py

From the "New Window", do a "Run" and then a "Run Module F5" and a wxPython GUI toolkit frame with the title "Bright Button" 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 panels and buttons inside the  wxPython GUI frame.

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"