Python turtle 模块,mainloop() 实例源码

我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用turtle.mainloop()

项目:Leetcode    作者:Shuailong    | 项目源码 | 文件源码
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()
项目:linedraw    作者:LingDong-    | 项目源码 | 文件源码
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()
项目:MyKnowledge    作者:guofei9987    | 项目源码 | 文件源码
def main():
    turtle.tracer(False)
    Init()
    SetupClock(160)
    turtle.tracer(True)
    Tick()
    turtle.mainloop()
项目:leetcode    作者:misaka-10032    | 项目源码 | 文件源码
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()
项目:LeetCode    作者:YJL33    | 项目源码 | 文件源码
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()
项目:particle_filter    作者:rcorona    | 项目源码 | 文件源码
def run(self):
        turtle.mainloop()
项目:IntroPython2016a    作者:UWPCE-PythonCert    | 项目源码 | 文件源码
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()
项目:IntroPython2016a    作者:UWPCE-PythonCert    | 项目源码 | 文件源码
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()
项目:IntroPython2016a    作者:UWPCE-PythonCert    | 项目源码 | 文件源码
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()
项目:jvcprojectortools    作者:arvehj    | 项目源码 | 文件源码
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