我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用turtle.mainloop()。
def drawtree(root): def height(root): return 1 + max(height(root.left), height(root.right)) if root else -1 def jumpto(x, y): t.penup() t.goto(x, y) t.pendown() def draw(node, x, y, dx): if node: t.goto(x, y) jumpto(x, y-20) t.write(node.val, align='center', font=('Arial', 12, 'normal')) draw(node.left, x-dx, y-60, dx/2) jumpto(x, y-20) draw(node.right, x+dx, y-60, dx/2) import turtle t = turtle.Turtle() t.speed(0); turtle.delay(0) h = height(root) jumpto(0, 30*h) draw(root, 0, 30*h, 40*h) t.hideturtle() turtle.mainloop()
def visualize(lines): import turtle wn = turtle.Screen() t = turtle.Turtle() t.speed(0) t.pencolor('red') t.pd() for i in range(0,len(lines)): for p in lines[i]: t.goto(p[0]*640/1024-320,-(p[1]*640/1024-320)) t.pencolor('black') t.pencolor('red') turtle.mainloop()
def main(): turtle.tracer(False) Init() SetupClock(160) turtle.tracer(True) Tick() turtle.mainloop()
def drawtree(root): def height(root): return 1 + max(height(root.left), height(root.right)) if root else -1 def jumpto(x, y): t.penup() t.goto(x, y) t.pendown() def draw(node, x, y, dx): if node: t.goto(x, y) jumpto(x, y - 20) t.write(node.val, align='center', font=('Arial', 12, 'normal')) draw(node.left, x - dx, y - 60, dx / 2) jumpto(x, y - 20) draw(node.right, x + dx, y - 60, dx / 2) import turtle t = turtle.Turtle() t.speed(0) turtle.delay(0) h = height(root) jumpto(0, 30 * h) draw(root, 0, 30 * h, 40 * h) t.hideturtle() turtle.mainloop()
def run(self): turtle.mainloop()
def rectangle(t,length,width): for i in range(2): t.fd(length) t.lt(90) t.fd(width) t.lt(90) print(bob) turtle.mainloop()
def mypolygon(t,sides,length): angle = 360 /sides t.fd(length/8) for i in range(sides): t.fd(length) t.lt(angle) print(alice) turtle.mainloop()
def mycircle(t,radius,sides): t.fd(radius) for i in range(sides): t.fd(radius*3/2) t.lt(360/sides) print(alice) turtle.mainloop()
def run(self): """Process command queue and enter turtle main loop""" if self.closed: raise PlotClosed('Plot window closed') opened = False try: while True: try: cmd = self.queue.get(timeout=1) break except queue.Empty: pass if cmd != self.do_close: opened = True self.do_zoom() self.do_clear() cmd() turtle.ontimer(self.check_queue, 100) turtle.mainloop() except turtle.Terminator: pass except KeyboardInterrupt: pass finally: self.closed = True if opened: try: turtle.bye() except turtle.Terminator: pass