Turtle Graphics:Onscreenclick 不起作用
Turtle Graphics: Onscreenclick doesn't work
학번, 이름, 전공
def Color():
import random as r
color=['yellow','red','blue','black','green'] #5색
return r.choice(color)
def Shape():
import turtle as t
import random as r
t.up()
t.onscreenclick(t.goto) #클릭한 곳으로 거북이 이동
t.pencolor(Color()) #펜 색깔 결정
t.down()
t.speed('fastest') #가장 빠른 속도로 거북이 설정
shape = [0,3,4,5,6]
result = r.choice(shape)
line=r.randint(50,100) #50에서 100중에 random으로 반지름/변의 길이 설정
import turtle as t #turtle graphic import
import random as r #random import
t.onscreenclick(t.goto)
Shape()
if (t.onkeypress("Space")) : #Space를 눌렀을 때 채우기 함수 실행
t.onscreenclick(Fill())
if (t.onkeypress("Space")):
t.onscreenclick(Shape())
if (t.onscreenclick("c")):
Clear()
t.mainloop()
它说 Tkinter 回调中的异常
追溯(最近一次通话):
文件“C:\Users\suyeo\AppData\Local\Programs\Python\Python39\lib\tkinter_init_.py”,第 1892 行,在 call 中
return self.func(*参数)
文件“C:\Users\suyeo\AppData\Local\Programs\Python\Python39\lib\turtle.py”,第 674 行,在 eventfun 中
乐趣(x,y)
类型错误:'str' 对象不可调用
onscreenclick
and onkeypress
设置回调 - 当这些事件发生时调用的函数。您只需为每个事件或键调用这些函数一次——除非您需要修改它们。 AFAIK,它们没有 return 任何值。 onscreenclick
接受一个参数:一个函数接受 2 个参数,x
和 y
坐标。 onkeypress
接受 2 个参数:回调函数和密钥。
import turtle as t
import random as r
def fill():
# TODO: Add your code here
pass
def clear():
# TODO: Add your code here
pass
def color():
color=['yellow','red','blue','black','green']
return r.choice(color)
def shape(x, y):
t.pencolor(color())
t.goto(x, y)
t.speed('fastest')
# Setup the callbacks. The first parameter to each is a function "pointer"
t.onscreenclick(shape)
t.onkeypress(fill, "space")
t.onkeypress(clear, "c")
shape(0, 0)
t.listen()
t.mainloop()
학번, 이름, 전공
def Color():
import random as r
color=['yellow','red','blue','black','green'] #5색
return r.choice(color)
def Shape():
import turtle as t
import random as r
t.up()
t.onscreenclick(t.goto) #클릭한 곳으로 거북이 이동
t.pencolor(Color()) #펜 색깔 결정
t.down()
t.speed('fastest') #가장 빠른 속도로 거북이 설정
shape = [0,3,4,5,6]
result = r.choice(shape)
line=r.randint(50,100) #50에서 100중에 random으로 반지름/변의 길이 설정
import turtle as t #turtle graphic import
import random as r #random import
t.onscreenclick(t.goto)
Shape()
if (t.onkeypress("Space")) : #Space를 눌렀을 때 채우기 함수 실행
t.onscreenclick(Fill())
if (t.onkeypress("Space")):
t.onscreenclick(Shape())
if (t.onscreenclick("c")):
Clear()
t.mainloop()
它说 Tkinter 回调中的异常 追溯(最近一次通话): 文件“C:\Users\suyeo\AppData\Local\Programs\Python\Python39\lib\tkinter_init_.py”,第 1892 行,在 call 中 return self.func(*参数) 文件“C:\Users\suyeo\AppData\Local\Programs\Python\Python39\lib\turtle.py”,第 674 行,在 eventfun 中 乐趣(x,y) 类型错误:'str' 对象不可调用
onscreenclick
and onkeypress
设置回调 - 当这些事件发生时调用的函数。您只需为每个事件或键调用这些函数一次——除非您需要修改它们。 AFAIK,它们没有 return 任何值。 onscreenclick
接受一个参数:一个函数接受 2 个参数,x
和 y
坐标。 onkeypress
接受 2 个参数:回调函数和密钥。
import turtle as t
import random as r
def fill():
# TODO: Add your code here
pass
def clear():
# TODO: Add your code here
pass
def color():
color=['yellow','red','blue','black','green']
return r.choice(color)
def shape(x, y):
t.pencolor(color())
t.goto(x, y)
t.speed('fastest')
# Setup the callbacks. The first parameter to each is a function "pointer"
t.onscreenclick(shape)
t.onkeypress(fill, "space")
t.onkeypress(clear, "c")
shape(0, 0)
t.listen()
t.mainloop()