當前位置: 首頁>>代碼示例>>Python>>正文


Python turtle.listen方法代碼示例

本文整理匯總了Python中turtle.listen方法的典型用法代碼示例。如果您正苦於以下問題:Python turtle.listen方法的具體用法?Python turtle.listen怎麽用?Python turtle.listen使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在turtle的用法示例。


在下文中一共展示了turtle.listen方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import listen [as 別名]
def __init__(
                self,
                screen_width = 800,
                screen_height = 600,
                background_color = "black",
                title = "Simple Game Library by /u/wynand1004 AKA @TokyoEdTech",
                splash_time = 3):

        # Setup using Turtle module methods
        turtle.setup(width=screen_width, height=screen_height)
        turtle.bgcolor(background_color)
        turtle.title(title)
        turtle.tracer(0) # Stop automatic screen refresh
        turtle.listen() # Listen for keyboard input
        turtle.hideturtle() # Hides default turtle
        turtle.penup() # Puts pen up for defaut turtle
        turtle.setundobuffer(0) # Do not keep turtle history in memory
        turtle.onscreenclick(self.click)

        # Game Attributes
        self.SCREEN_WIDTH = screen_width
        self.SCREEN_HEIGHT = screen_height
        self.DATAFILE = "game.dat"
        self.SPLASHFILE = "splash.gif" # Must be in the same folder as game file

        self.fps = 30.0 # Lower this on slower computers or with large number of sprites
        self.title = title
        self.gravity = 0
        self.state = "showsplash"
        self.splash_time = splash_time

        self.time = time.time()

        # Clear the terminal and print the game title
        self.clear_terminal_screen()
        print (self.title)

        # Show splash
        self.show_splash(self.splash_time)

    # Pop ups 
開發者ID:wynand1004,項目名稱:SPGL,代碼行數:43,代碼來源:spgl.py

示例2: on_left

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import listen [as 別名]
def on_left():
    val = t.textinput('Left', "How much: ")
    if val:
        try:
            val = int(val)
            t.left(val)
        except ValueError:
            messagebox.showinfo('Error', 'Wrong value')
    t.listen() 
開發者ID:furas,項目名稱:python-examples,代碼行數:11,代碼來源:main.py

示例3: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import listen [as 別名]
def __init__(
                self,
                screen_width = 800,
                screen_height = 600,
                background_color = "black",
                title = "Simple Game Library by /u/wynand1004 AKA @TokyoEdTech",
                splash_time = 3):

        # Setup using Turtle module methods
        turtle.setup(width=screen_width, height=screen_height)
        turtle.bgcolor(background_color)
        turtle.title(title)
        turtle.tracer(0) # Stop automatic screen refresh
        turtle.listen() # Listen for keyboard input
        turtle.hideturtle() # Hides default turtle
        turtle.penup() # Puts pen up for defaut turtle
        turtle.setundobuffer(0) # Do not keep turtle history in memory
        turtle.onscreenclick(self.click)

        # Game Attributes
        self.FPS = 30.0 # Lower this on slower computers or with large number of sprites
        self.SCREEN_WIDTH = screen_width
        self.SCREEN_HEIGHT = screen_height
        self.DATAFILE = "game.dat"
        self.SPLASHFILE = "splash.gif" # Must be in the same folder as game file

        self.title = title
        self.gravity = 0
        self.state = "showsplash"
        self.splash_time = splash_time

        self.time = time.time()

        # Clear the terminal and print the game title
        self.clear_terminal_screen()
        print (self.title)

        # Show splash
        self.show_splash(self.splash_time)

    # Pop ups 
開發者ID:wynand1004,項目名稱:SPGL,代碼行數:43,代碼來源:spgl.py

示例4: on_forward

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import listen [as 別名]
def on_forward():
    val = t.textinput('Forward', "How much: ")
    if val:
        try:
            val = int(val)
            t.forward(val)
        except ValueError:
            messagebox.showinfo('Error', 'Wrong value')
    t.listen() 
開發者ID:furas,項目名稱:python-examples,代碼行數:11,代碼來源:main.py

示例5: on_backward

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import listen [as 別名]
def on_backward():
    val = t.textinput('Backward', "How much: ")
    if val:
        try:
            val = int(val)
            t.backward(val)
        except ValueError:
            messagebox.showinfo('Error', 'Wrong value')
    t.listen() 
開發者ID:furas,項目名稱:python-examples,代碼行數:11,代碼來源:main.py

示例6: on_right

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import listen [as 別名]
def on_right():
    val = t.textinput('Right', "How much: ")
    if val:
        try:
            val = int(val)
            t.right(val)
        except ValueError:
            messagebox.showinfo('Error', 'Wrong value')
    t.listen() 
開發者ID:furas,項目名稱:python-examples,代碼行數:11,代碼來源:main.py

示例7: main

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import listen [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.listen方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。