我正在努力创造琼脂特金特的比赛。我试图用光标移动一个圆,但我得到了这个错误。你知道吗
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1541, in __call__
return self.func(*args)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 592, in callit
func(*args)
File "/Users/Hari/Desktop/Agario.py", line 32, in move1
g1, g2 = cursor()
TypeError: cursor() takes exactly 1 argument (0 given)
这是我的密码。这是不完整的,我只是想得到移动我的光标键绑定完成,然后我将继续移动圆本身
import Tkinter
from random import randint
tk=Tkinter.Tk()
canvas=Tkinter.Canvas(width=1250, height=700)
canvas.configure(background='red')
frame=canvas.create_rectangle(10,10,1240,690, fill="white")
om=canvas.create_oval(50,50,75,75, fill="blue")
lis=[]
count=0
on=0
def move1():
global lis, count, on
count=count+1
if(count%100==0):
c1=randint(10,1235)
c2=randint(10,685)
o=canvas.create_oval(c1,c2,c1+5,c2+5, fill="green")
lis1=[]
lis1.append(c1)
lis1.append(c2)
lis1.append(c1+5)
lis1.append(c2+5)
lis.append(lis1)
g1, g2 = cursor()
print g1, g2
x1, y1, x2, y2=canvas.coords(om)
canvas.after(1,move1)
move1()
def cursor(event):
m1=event.x
m2=event.y
return m1, m2
tk.bind("<B1-Motion>", cursor)
canvas.pack()
tk.mainloop()
您应该从字面上理解此错误消息。 “cursor()正好接受1个参数(给定0)”消息的意思是 游标函数被定义为接受事件作为参数
def cursor(event):
但是你不用任何参数就可以叫它g1, g2 = cursor()
相关问题 更多 >
编程相关推荐