|
53 | 53 |
|
54 | 54 | (2) How to add your own demos to the demo repository |
55 | 55 |
|
56 | | - - place: same directory as turtledemo/__main__.py |
| 56 | + - Place the file in the same directory as turtledemo/__main__.py |
57 | 57 |
|
58 | | - - requirements on source code: |
59 | | - code must contain a main() function which will |
60 | | - be executed by the viewer (see provided example scripts) |
61 | | - main() may return a string which will be displayed |
62 | | - in the Label below the source code window (when execution |
63 | | - has finished.) |
| 58 | + - The code must contain a main() function which will |
| 59 | + be executed by the viewer (see provided example scripts). |
| 60 | + It may return a string which will be displayed in the Label below |
| 61 | + the source code window (when execution has finished.) |
64 | 62 |
|
65 | | - If the demo is EVENT DRIVEN, main must return the string |
66 | | - "EVENTLOOP". This informs the demo viewer that the script is |
67 | | - still running and must be stopped by the user! |
| 63 | + - In order to run mydemo.py by itself, such as during development, |
| 64 | + add the following at the end of the file: |
68 | 65 |
|
69 | | - If an "EVENTLOOP" demo runs by itself, as with clock, which uses |
70 | | - ontimer, or minimal_hanoi, which loops by recursion, then the |
71 | | - code should catch the turtle.Terminator exception that will be |
72 | | - raised when the user presses the STOP button. (Paint is not such |
73 | | - a demo; it only acts in response to mouse clicks and movements.) |
| 66 | + if __name__ == '__main__': |
| 67 | + main() |
| 68 | + mainloop() # keep window |
74 | 69 |
|
| 70 | + python -m turtledemo.mydemo # will then run it |
| 71 | + |
| 72 | + - If the demo is EVENT DRIVEN, main must return the string |
| 73 | + "EVENTLOOP". This informs the demo viewer that the script is |
| 74 | + still running and must be stopped by the user! |
| 75 | + |
| 76 | + If an "EVENTLOOP" demo runs by itself, as with clock, which uses |
| 77 | + ontimer, or minimal_hanoi, which loops by recursion, then the |
| 78 | + code should catch the turtle.Terminator exception that will be |
| 79 | + raised when the user presses the STOP button. (Paint is not such |
| 80 | + a demo; it only acts in response to mouse clicks and movements.) |
0 commit comments