我试图在tkinter中创建agar.io游戏。我试图用我的光标移动一个圆圈,但我得到了这个错误。
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()
答案 0 :(得分:0)
您应该从字面上理解此错误消息。
“cursor()只取一个参数(0给定)”消息的意思
将游标函数定义为接受事件为参数def cursor(event):
但是你没有任何参数g1, g2 = cursor()