| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -140,7 +140,7 @@ | |||
| 140 | 140 | _tg_utilities = ['write_docstringdict', 'done'] | |
| 141 | 141 | ||
| 142 | 142 | __all__ = (_tg_classes + _tg_screen_functions + _tg_turtle_functions + | |
| 143 | - _tg_utilities) # + _math_functions) | ||
| 143 | + _tg_utilities + ['Terminator']) # + _math_functions) | ||
| 144 | 144 | ||
| 145 | 145 | _alias_list = ['addshape', 'backward', 'bk', 'fd', 'ht', 'lt', 'pd', 'pos', | |
| 146 | 146 | 'pu', 'rt', 'seth', 'setpos', 'setposition', 'st', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -11,11 +11,8 @@ | |||
| 11 | 11 | ------------------------------------ | |
| 12 | 12 | """ | |
| 13 | 13 | from turtle import * | |
| 14 | - from turtle import Terminator # not in __all__ | ||
| 15 | 14 | from datetime import datetime | |
| 16 | 15 | ||
| 17 | - mode("logo") | ||
| 18 | - | ||
| 19 | 16 | def jump(distanz, winkel=0): | |
| 20 | 17 | penup() | |
| 21 | 18 | right(winkel) | |
@@ -43,7 +40,6 @@ def make_hand_shape(name, laenge, spitze): | |||
| 43 | 40 | hand_form = get_poly() | |
| 44 | 41 | register_shape(name, hand_form) | |
| 45 | 42 | ||
| 46 | - | ||
| 47 | 43 | def clockface(radius): | |
| 48 | 44 | reset() | |
| 49 | 45 | pensize(7) | |
@@ -84,7 +80,6 @@ def setup(): | |||
| 84 | 80 | writer.pu() | |
| 85 | 81 | writer.bk(85) | |
| 86 | 82 | ||
| 87 | - | ||
| 88 | 83 | def wochentag(t): | |
| 89 | 84 | wochentag = ["Monday", "Tuesday", "Wednesday", | |
| 90 | 85 | "Thursday", "Friday", "Saturday", "Sunday"] | |
@@ -131,6 +126,7 @@ def main(): | |||
| 131 | 126 | return "EVENTLOOP" | |
| 132 | 127 | ||
| 133 | 128 | if __name__ == "__main__": | |
| 129 | + mode("logo") | ||
| 134 | 130 | msg = main() | |
| 135 | 131 | print(msg) | |
| 136 | 132 | mainloop() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,8 +1,6 @@ | |||
| 1 | 1 | # colormixer | |
| 2 | 2 | ||
| 3 | 3 | from turtle import Screen, Turtle, mainloop | |
| 4 | - import sys | ||
| 5 | - sys.setrecursionlimit(20000) # overcomes, for now, an instability of Python 3.0 | ||
| 6 | 4 | ||
| 7 | 5 | class ColorTurtle(Turtle): | |
| 8 | 6 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,6 +54,9 @@ | |||
| 54 | 54 | (2) How to add your own demos to the demo repository | |
| 55 | 55 | ||
| 56 | 56 | - Place the file in the same directory as turtledemo/__main__.py | |
| 57 | + IMPORTANT! When imported, the demo should not modify the system | ||
| 58 | + by calling functions in other modules, such as sys, tkinter, or | ||
| 59 | + turtle. Global variables should be initialized in main(). | ||
| 57 | 60 | ||
| 58 | 61 | - The code must contain a main() function which will | |
| 59 | 62 | be executed by the viewer (see provided example scripts). | |
@@ -65,7 +68,7 @@ | |||
| 65 | 68 | ||
| 66 | 69 | if __name__ == '__main__': | |
| 67 | 70 | main() | |
| 68 | - mainloop() # keep window | ||
| 71 | + mainloop() # keep window open | ||
| 69 | 72 | ||
| 70 | 73 | python -m turtledemo.mydemo # will then run it | |
| 71 | 74 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -18,7 +18,6 @@ | |||
| 18 | 18 | --------------------------------------- | |
| 19 | 19 | """ | |
| 20 | 20 | from turtle import * | |
| 21 | - from turtle import Terminator # not in __all__ | ||
| 22 | 21 | ||
| 23 | 22 | class Disc(Turtle): | |
| 24 | 23 | def __init__(self, n): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -143,7 +143,6 @@ def display(self, msg1, msg2=None): | |||
| 143 | 143 | self.writer.write(msg1, align="center", font=("Courier",14,"bold")) | |
| 144 | 144 | self.screen.tracer(True) | |
| 145 | 145 | ||
| 146 | - | ||
| 147 | 146 | def setup(self): | |
| 148 | 147 | self.screen.tracer(False) | |
| 149 | 148 | for row in range(3): | |
@@ -181,6 +180,7 @@ def clear(self): | |||
| 181 | 180 | if self.game.state == Nim.OVER: | |
| 182 | 181 | self.screen.clear() | |
| 183 | 182 | ||
| 183 | + | ||
| 184 | 184 | class NimController(object): | |
| 185 | 185 | ||
| 186 | 186 | def __init__(self, game): | |
@@ -201,6 +201,7 @@ def notify_move(self, row, col): | |||
| 201 | 201 | self.game.model.notify_move(row, col) | |
| 202 | 202 | self.BUSY = False | |
| 203 | 203 | ||
| 204 | + | ||
| 204 | 205 | class Nim(object): | |
| 205 | 206 | CREATED = 0 | |
| 206 | 207 | RUNNING = 1 | |
@@ -213,11 +214,10 @@ def __init__(self, screen): | |||
| 213 | 214 | self.controller = NimController(self) | |
| 214 | 215 | ||
| 215 | 216 | ||
| 216 | - mainscreen = turtle.Screen() | ||
| 217 | - mainscreen.mode("standard") | ||
| 218 | - mainscreen.setup(SCREENWIDTH, SCREENHEIGHT) | ||
| 219 | - | ||
| 220 | 217 | def main(): | |
| 218 | + mainscreen = turtle.Screen() | ||
| 219 | + mainscreen.mode("standard") | ||
| 220 | + mainscreen.setup(SCREENWIDTH, SCREENHEIGHT) | ||
| 221 | 221 | nim = Nim(mainscreen) | |
| 222 | 222 | return "EVENTLOOP!" | |
| 223 | 223 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,60 +1,54 @@ | |||
| 1 | 1 | """turtledemo.two_canvases | |
| 2 | 2 | ||
| 3 | 3 | Use TurtleScreen and RawTurtle to draw on two | |
| 4 | - distinct canvases. | ||
| 4 | + distinct canvases in a separate windows. The | ||
| 5 | + new window must be separately closed in | ||
| 6 | + addition to pressing the STOP button. | ||
| 5 | 7 | """ | |
| 6 | - #The final mainloop only serves to keep the window open. | ||
| 7 | - | ||
| 8 | - #TODO: This runs in its own two-canvas window when selected in the | ||
| 9 | - #demoviewer examples menu but the text is not loaded and the previous | ||
| 10 | - #example is left visible. If the ending mainloop is removed, the text | ||
| 11 | - #Eis loaded, this run again in a third window, and if start is pressed, | ||
| 12 | - #demoviewer raises an error because main is not found, and then freezes. | ||
| 13 | 8 | ||
| 14 | 9 | from turtle import TurtleScreen, RawTurtle, TK | |
| 15 | 10 | ||
| 16 | - root = TK.Tk() | ||
| 17 | - cv1 = TK.Canvas(root, width=300, height=200, bg="#ddffff") | ||
| 18 | - cv2 = TK.Canvas(root, width=300, height=200, bg="#ffeeee") | ||
| 19 | - cv1.pack() | ||
| 20 | - cv2.pack() | ||
| 11 | + def main(): | ||
| 12 | + root = TK.Tk() | ||
| 13 | + cv1 = TK.Canvas(root, width=300, height=200, bg="#ddffff") | ||
| 14 | + cv2 = TK.Canvas(root, width=300, height=200, bg="#ffeeee") | ||
| 15 | + cv1.pack() | ||
| 16 | + cv2.pack() | ||
| 21 | 17 | ||
| 22 | - s1 = TurtleScreen(cv1) | ||
| 23 | - s1.bgcolor(0.85, 0.85, 1) | ||
| 24 | - s2 = TurtleScreen(cv2) | ||
| 25 | - s2.bgcolor(1, 0.85, 0.85) | ||
| 18 | + s1 = TurtleScreen(cv1) | ||
| 19 | + s1.bgcolor(0.85, 0.85, 1) | ||
| 20 | + s2 = TurtleScreen(cv2) | ||
| 21 | + s2.bgcolor(1, 0.85, 0.85) | ||
| 26 | 22 | ||
| 27 | - p = RawTurtle(s1) | ||
| 28 | - q = RawTurtle(s2) | ||
| 23 | + p = RawTurtle(s1) | ||
| 24 | + q = RawTurtle(s2) | ||
| 29 | 25 | ||
| 30 | - p.color("red", (1, 0.85, 0.85)) | ||
| 31 | - p.width(3) | ||
| 32 | - q.color("blue", (0.85, 0.85, 1)) | ||
| 33 | - q.width(3) | ||
| 26 | + p.color("red", (1, 0.85, 0.85)) | ||
| 27 | + p.width(3) | ||
| 28 | + q.color("blue", (0.85, 0.85, 1)) | ||
| 29 | + q.width(3) | ||
| 34 | 30 | ||
| 35 | - for t in p,q: | ||
| 36 | - t.shape("turtle") | ||
| 37 | - t.lt(36) | ||
| 31 | + for t in p,q: | ||
| 32 | + t.shape("turtle") | ||
| 33 | + t.lt(36) | ||
| 38 | 34 | ||
| 39 | - q.lt(180) | ||
| 35 | + q.lt(180) | ||
| 40 | 36 | ||
| 41 | - for t in p, q: | ||
| 42 | - t.begin_fill() | ||
| 43 | - for i in range(5): | ||
| 44 | 37 | for t in p, q: | |
| 45 | - t.fd(50) | ||
| 46 | - t.lt(72) | ||
| 47 | - for t in p,q: | ||
| 48 | - t.end_fill() | ||
| 49 | - t.lt(54) | ||
| 50 | - t.pu() | ||
| 51 | - t.bk(50) | ||
| 52 | - | ||
| 53 | - ## Want to get some info? | ||
| 54 | - | ||
| 55 | - #print(s1, s2) | ||
| 56 | - #print(p, q) | ||
| 57 | - #print(s1.turtles()) | ||
| 58 | - #print(s2.turtles()) | ||
| 59 | - | ||
| 60 | - TK.mainloop() | ||
| 38 | + t.begin_fill() | ||
| 39 | + for i in range(5): | ||
| 40 | + for t in p, q: | ||
| 41 | + t.fd(50) | ||
| 42 | + t.lt(72) | ||
| 43 | + for t in p,q: | ||
| 44 | + t.end_fill() | ||
| 45 | + t.lt(54) | ||
| 46 | + t.pu() | ||
| 47 | + t.bk(50) | ||
| 48 | + | ||
| 49 | + return "EVENTLOOP" | ||
| 50 | + | ||
| 51 | + | ||
| 52 | + if __name__ == '__main__': | ||
| 53 | + main() | ||
| 54 | + TK.mainloop() # keep window open until user closes it | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments