1. Install Python 2.5.1 on Microsoft Windows
2. Run a one-line "Hello World" interactive program
3. Pop up a "Hello World" Windows Message Box.
4. Pop up a two-button Windows dialog box which interacts with your program.
5. Learn where to find more tutorials and documentation
The first 4 of these can be done in 3 minutes if you are focused!
This is a cookbook. Before "cooking" the recipe, you need a few ingredients:
1. Get the python installer at Python 2.5.1 Windows installer.
2. Create a folder, and know its location. Mine is at D:\b\Wins
3. Copy the following program, paste it into an editor and save it as a file in the folder.
CODE
from Tkinter import *
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red", bg="yellow",
command=master.destroy)
self.button.pack(side=LEFT)
self.hello = Button(frame, text="Hello", command=self.say_hi)
self.hello.pack()
def say_hi(self):
print "Hello, new Python programmer!"
root = Tk()
app = App(root)
root.mainloop()
class App:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red", bg="yellow",
command=master.destroy)
self.button.pack(side=LEFT)
self.hello = Button(frame, text="Hello", command=self.say_hi)
self.hello.pack()
def say_hi(self):
print "Hello, new Python programmer!"
root = Tk()
app = App(root)
root.mainloop()
I saved it as D:\b\Wins\Buttons.py
Do the preceding things to prepare for the 3 minutes. There are additional items you may need if you are on an earlier Windows platform. If your platform does not recognize a .msi Windows installer file, you may need Windows Installer 2.0 Redistributable for Windows 95, 98, and Me, or a later version for Windows 2000 or NT. The text editor you use to save the program should not convert blanks to tabs. White space is significant in Python programs, and there is no standard for how many blanks equals one tab.
Recipe:
Ready to go? Start your stopwatch!
1. Double-click the Python installer. (Take all defaults.)
- It asks whether to install for just you, or all users. Take the default (all users).
- It asks whether to install only parts of the package. Take the default (all packages).
- It asks where to install. Take the default (C:\Python25)
- Tell it to do the install. Click Finish. Total elapsed time 35 seconds on my computer.
- Type the following text into the Python Shell: print "Hello world!" Hit Return.
- Python will respond by doing what you told it to do.
- Congratulations, you have run your first Python program! Elapsed time 1 minute.
- Note the syntax highlighting and argument prompts that occur as you type.
- When you hit the Enter key after the last line, a window will pop up. It can easily become hidden under the Python Shell window. If so, click on the "tk" item on the task bar.
- Close it. This will return control to the Shell. Elapsed time 2 minutes.
- Click Open. A new window will open, showing the file.
- Press the F5 function key on the keyboard.
- The Shell will come to the top of other windows, and a two-button window will pop up.
- Explore the two-button window, but first note the time on your watch: Total elapsed time: 3 minutes!
CODE
from Tkinter import *
root = Tk()
w = Label(root, text="Hello world!")
w.pack()
root.mainloop()
root = Tk()
w = Label(root, text="Hello world!")
w.pack()
root.mainloop()
This five-line program creates a label window using standard Windows system calls and messages. The iconize, minimize, and close buttons function as usual. Clicking the top-left corner of the window produces the same menu as right-clicking the task bar button. If you want to play with it some more, do the following:
Copy the text (from here, not from the Shell). From the menu on the Buttons.py window, select File | New Window and paste the text into that window. Then select File | Save As and give it a File Name ending in ".py". It will be saved in the same folder as Buttons.py.
The Buttons.py program puts two buttons in a frame. One, which closes the window, is given unusual colors. The other performs a "call-back," executing the "say_hi" method when it is pressed.
I have been programming for 50 years. Python is by far the easiest, most productive, least-error-prone language I have ever used. However, like any language, it must be learned. More complex tasks require more study. Fortunately, there are many excellent tutorials, and comprehensive documentation. Here are a few resources:
In any Python window, click Help | Python Docs | Tutorial. Alternatively, when any Python window has focus, press the F1 function key. The tutorial will introduce you to basic, and not-so-basic Python tools. The Global Module Index introduces you to many available resources, like Tkinter. And yes, all of this came in that 10 MB package you installed!
For the essentials of pop-up windows on a Microsoft platform, see: An Introduction to Tkinter .
Most of these programming tools also work on Linux, Mac, Java, .NET and many other platforms.
Enjoy!

