Python turtle.mainloop() Examples
The following are 4
code examples of turtle.mainloop().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
turtle
, or try the search function
.
Example #1
Source File: clock.py From Tools with MIT License | 8 votes |
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()
Example #2
Source File: strokesort.py From linedraw with MIT License | 5 votes |
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()
Example #3
Source File: Pikachu.py From Python-Painting-Doraemon with MIT License | 5 votes |
def main(): print('Painting the Pikachu... ') turtle.screensize(800, 600) turtle.title('Pikachu') pikachu = Pikachu() pikachu.start() turtle.mainloop()
Example #4
Source File: spiro.py From Python-Project with Apache License 2.0 | 4 votes |
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