Eventually, your program will look like other programs. It will have an icon which people click on and which makes it run.
For now, though, we will be working from the command line -- interactive mode.
Note: If you are working on a system with a reasonable text terminal (BSD, Linux, etc) you may want to use that instead of interact.py for these interactive sessions. Simply open a terminal in the examples directory, type python then type from penguin import *
注意:如果你工作在正当的文本终端(BSD,Linux,etc)上，你也许希望终端可以替代interact.py来做交互式的会话。在examples目录中打开一个终端，运行python然后键入from penguin import *
After that everything should be much the same as with using interact.py except you will have better text editing capabilities.
The interactive interpreter is a way to type in python commands and get results immediately.
Look in the pygsear examples directory, and run the program called interact.py. You should get a new window with a little penguin in the middle of the screen.
The >>> in the lower left corner is called the prompt. It is the Python interpreter waiting for you to tell it what to do.
We are going to start with something called "turtle" graphics. Oddly enough, our turtle will look like a penguin.
The penguin is called pete.
Let's start out by having pete draw a line. Type in this line and press [ENTER]:
This statement is a function call or method call. It tells pete to move forward 100 pixels.
You can put any number you want inside the parentheses (even negative numbers), but keep in mind that the window that pete is drawing in is probably only about 600 pixels wide and 500 pixels high.
We can also make pete turn:
pete understands turning in degrees, so when we tell pete right(30), he turns 30 degrees to his right.
Notice that the amount is relative to where pete is looking when you ask him to turn. That means that if you say pete.right(30) again, pete will turn a bit more to the right, and if you do pete.right(30) one more time he will have turned a total of 90 degrees and be looking over at the right side of the screen.
Reset the penguin graphics now by typing:
See if you can make pete go around in a square. How can you do that?
How about like this:
First, go forward again. Notice that by using the up and down arrows on your keyboard you can retrieve lines you typed previously and save yourself some typing. So, hit the up arrow until the line looks like pete.forward(100) again and hit [ENTER]
Of course a square is just four equal sides, and four right angles, so make pete turn right 90 degrees:
Now the simplest way to continue is just to keep hitting up-arrow twice and [ENTER] until pete is back to where he started.
Remember, if you make a mistake, or things get confused, don't worry. Just type:
pete will go back to where he started and clear the screen in the process.
You can also use home() to bring pete back to where he started without changing anything drawn on the screen, or cls() to erase everything but without making pete move at all.