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.
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.
-->
-->
-->
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