python类mainloop()的实例源码

tree_visualize.py 文件源码 项目:Leetcode 作者: Shuailong 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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()
strokesort.py 文件源码 项目:linedraw 作者: LingDong- 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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()
??.py 文件源码 项目:MyKnowledge 作者: guofei9987 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def main():
    turtle.tracer(False)
    Init()
    SetupClock(160)
    turtle.tracer(True)
    Tick()
    turtle.mainloop()
tree.py 文件源码 项目:leetcode 作者: misaka-10032 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
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()
testerForTree.py 文件源码 项目:LeetCode 作者: YJL33 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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_visualizer.py 文件源码 项目:particle_filter 作者: rcorona 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def run(self):
        turtle.mainloop()
mypolygon.py 文件源码 项目:IntroPython2016a 作者: UWPCE-PythonCert 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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()
mypolygon.py 文件源码 项目:IntroPython2016a 作者: UWPCE-PythonCert 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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()
mypolygon.py 文件源码 项目:IntroPython2016a 作者: UWPCE-PythonCert 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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()
plot.py 文件源码 项目:jvcprojectortools 作者: arvehj 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号