当前位置: 首页>>代码示例>>Python>>正文


Python turtle.mainloop方法代码示例

本文整理汇总了Python中turtle.mainloop方法的典型用法代码示例。如果您正苦于以下问题:Python turtle.mainloop方法的具体用法?Python turtle.mainloop怎么用?Python turtle.mainloop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在turtle的用法示例。


在下文中一共展示了turtle.mainloop方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: start

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import mainloop [as 别名]
def start():
	# 不显示绘制时钟的过程
	turtle.tracer(False)
	turtle.mode('logo')
	createHand('second_hand', 150)
	createHand('minute_hand', 125)
	createHand('hour_hand', 85)
	# 秒, 分, 时
	second_hand = turtle.Turtle()
	second_hand.shape('second_hand')
	minute_hand = turtle.Turtle()
	minute_hand.shape('minute_hand')
	hour_hand = turtle.Turtle()
	hour_hand.shape('hour_hand')
	for hand in [second_hand, minute_hand, hour_hand]:
		hand.shapesize(1, 1, 3)
		hand.speed(0)
	# 用于打印日期等文字
	printer = turtle.Turtle()
	printer.hideturtle()
	printer.penup()
	createClock(160)
	# 开始显示轨迹
	turtle.tracer(True)
	startTick(second_hand, minute_hand, hour_hand, printer)
	turtle.mainloop() 
开发者ID:CharlesPikachu,项目名称:Tools,代码行数:28,代码来源:clock.py

示例2: main

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import mainloop [as 别名]
def main():
    print('Painting the Pikachu... ')
    turtle.screensize(800, 600)
    turtle.title('Pikachu')
    pikachu = Pikachu()
    pikachu.start()
    turtle.mainloop() 
开发者ID:PerpetualSmile,项目名称:Python-Painting-Doraemon,代码行数:9,代码来源:Pikachu.py

示例3: visualize

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import mainloop [as 别名]
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() 
开发者ID:LingDong-,项目名称:linedraw,代码行数:15,代码来源:strokesort.py

示例4: main

# 需要导入模块: import turtle [as 别名]
# 或者: from turtle import mainloop [as 别名]
def main():
    # use sys.argv if needed
    print('genterating spirograph...')
    # create parser
    descStr ="""This program draws spirographs using the Turtle module. 
    When run with no arguments, this program draws random spirographs.
    
    Terminology:
    R: radius of outer circle.
    r: radius of inner circle.
    l: ratio of hole distance to r."""
    parser = argparse.ArgumentParser(description=descStr) # 创建参数解析器对象

    parser.add_argument('--sparams',nargs=3,dest='sparams',required=False,
                        help="The three arguments in sparams:R,r,l.") # 向解析器添加可选参数

    # parse args
    args=parser.parse_args() # 调用函数进行实际的解析

    # set to 80% screen width
    turtle.setup(width=0.8)

    # set cursor shape
    turtle.shape('turtle')

    # set title
    turtle.title("Spirographs!")
    # add key handler for saving image
    turtle.onkey(saveDrawing,"s")
    # start listening
    turtle.listen()

    # hide main turtle cursor
    turtle.hideturtle()

    # checks args and draw # 首先检查是否有参数赋给--sparams.如果有,就从字符串中提取他们,用“列表解析”将他们转换成浮点数
    if args.sparams:
        params=[float(x) for x in args.sparams]
        # draw spirograph with given parameters
        # black by default
        col=(0.0,0.0,0.0)
        spiro=Spiro(0,0,col,*params)
        spiro.draw()

    else:
        # creat animator object
        spiroAnim=SpiroAnimator(4)
        # add key handler to toggle turtle cursor
        turtle.onkey(spiroAnim.toggleTurtles,"t")
        # add key handler to toggle turtle cursor
        turtle.onkey(spiroAnim.restart,"space")

    # start turtle main loop

        turtle.mainloop()


# call main 
开发者ID:DeqianBai,项目名称:Python-Project,代码行数:60,代码来源:spiro.py


注:本文中的turtle.mainloop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。