Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Install Python On Xp And Create Two Pop-up Windows In 3 Minutes!, See for yourself why Python is popular.
docduke
post Feb 21 2008, 12:10 AM
Post #1


Advanced Member
Group Icon

Group: [MODERATOR]
Posts: 102
Joined: 8-January 08
Member No.: 27,477



If you follow this tutorial you will:
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()

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.)
  1. It asks whether to install for just you, or all users. Take the default (all users).
  2. It asks whether to install only parts of the package. Take the default (all packages).
  3. It asks where to install. Take the default (C:\Python25)
  4. Tell it to do the install. Click Finish. Total elapsed time 35 seconds on my computer.
2. Click Start | All Programs | Python 2.5 | Idle (Python GUI).
  1. Type the following text into the Python Shell: print "Hello world!" Hit Return.
  2. Python will respond by doing what you told it to do.
  3. Congratulations, you have run your first Python program! Elapsed time 1 minute.
3. Next, type in the five-line program that appears below this outline. It is case-sensitive!
  1. Note the syntax highlighting and argument prompts that occur as you type.
  2. 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.
  3. Close it. This will return control to the Shell. Elapsed time 2 minutes.
4. From the Shell menu, select File | Open, navigate to the file you saved before, and select it. In my case, it is D:\b\Wins\Buttons.py
  1. Click Open. A new window will open, showing the file.
  2. Press the F5 function key on the keyboard.
  3. The Shell will come to the top of other windows, and a two-button window will pop up.
  4. 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()

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! biggrin.gif
Go to the top of the page
 
+Quote Post
OpaQue
post Feb 21 2008, 08:59 AM
Post #2


Administrator
Group Icon

Group: Admin
Posts: 458
Joined: 26-August 04
Member No.: 1



Python Completed in 4 hours. Well, I was not into it completely and while I was learning, I installed e-accelerator. Activated it on forums. Then learn't memcached module and how it works. Installed it on server and put some codes in forum config files to use it. Got 1 GB Ram on server shree installed by Theplanet engineers. tongue.gif

Thank you for the tutorial docduke :-).

The best part of python that I liked was the way it could get inside Windows Env. :-)
Go to the top of the page
 
+Quote Post
docduke
post Feb 21 2008, 03:48 PM
Post #3


Advanced Member
Group Icon

Group: [MODERATOR]
Posts: 102
Joined: 8-January 08
Member No.: 27,477



The main reason I put this tutorial up was to show how easy it can be to produce Windows code.

I'll never forget the first time I got set up to make Windows with Microsoft Visual Studio .NET. I tried to install it on a fresh install of Windows 2000 Pro. Wouldn't go -- said it needed .NET first. I tried installing .NET and got some cryptic error message. It turned out that .NET wouldn't go until I had Windows 2000 updated. It needed Service Release 3 or so, but the error message didn't tell me that. I think it took me 2 days to figure out how to get it done. Even then, the successful formula was to prevent a "reboot" when one of the partial installs asked for it, and proceed with the next install.

If I need to make a professional-looking window with all the components in just the right place, something like Visual Studio may be necessary. For just getting windows up with the necessary elements in default locations, Python is very much faster. There are books such as Python and Tkinter Programming that explain how to do detailed layout. Mark Hammond is responsible for really integrating Python into Windows. He is an author of another book, Python programming on Win32, which covers much more general programming on Windows. I remember reading somewhere that his tools are powerful enough that a programmer can fairly easily run a message loop exclusively in Python, and completely take control of a computer away from Microsoft!

Finally, the primary author of Python is Guido van Rossum. He was a professor in the Netherlands when he began it. Now he is in the U.S. tasked by Google to produce an improved version, Python 3.0. Python has been used in numerous commercial tasks, including movie-making and Google itself. There was a growing list of testimonials on the Python website, but it has now been replaced by a long, organized list of success stories.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Python (win32)(1)
  2. Create Your Own Shout Box(13)
  3. Help Needed To Create Login Script With Perl/cgi(21)
  4. How To Connect Dual/triple Monitor + Advantages(20)
  5. How To Play Mac Games On Windows And Vice-versa(26)
  6. How To Install Applications In Fedora(11)
  7. Pen Drive Ram On Windows Vista(13)
  8. How To Run Mac On Windows ?(14)
  9. The Best Version Of Windows(39)
  10. Windows Live Search(13)
  11. Windows XP Folder Encryption Key ?(13)
  12. Games For Samsung D900(1)
  13. Oracle 10g Install Issues(27)
  14. How Do I Create Static Routes In Windows Xp?(10)
  15. Windows Xp & Vista: Advantage Or Disadvantage(8)
  1. Looking For Linux(33)
  2. Dominos Delivery Marketing Scam(6)
  3. Making Xp Starts 60% Faster(3)
  4. How To Copy File & Folders From Linux To Windows?.(10)
  5. Linux For Beginners- Easy To Install(10)
  6. Strange Error When Trying To Install Fedora Core 9(4)
  7. Mccodes V2(2)
  8. How Do You Create A Vista?(12)
  9. How To Install Windows Xp Professional(2)
  10. Python Mysqldb Threading(0)
  11. Extremely Slow Hdd Operations On Windows Xp(8)
  12. Why I May Be Installing Windows Xp Sp3 Again(7)
  13. Image Problems With Windows 2000(5)


 



- Lo-Fi Version Time is now: 24th July 2008 - 12:11 PM