代码:
import tkinter
window = tkinter.Tk()
c = tkinter.Canvas(window, height=400, width=600, bg='green')
mid_x = 600 / 2
mid_y = 400 / 2
window.geometry("600x400")
window.title("window")
def ship_control(event):
pass
c.bind_all('<KeyPress-a>', ship_control)
def start():
global ship
rock_speed = 10
ship = c.create_oval(mid_x, mid_y, mid_x + 20, mid_y + 20, fill='red', outline='orange')
button_start = tkinter.Button(window, text='play', command=start)
button_start.pack()
c.pack()
错误:
>>>
>>> Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Program Files\Python 3.5\lib\idlelib\run.py", line 121, in main
seq, request = rpc.request_queue.get(block=True, timeout=0.05)
File "C:\Program Files\Python 3.5\lib\queue.py", line 172, in get
raise Empty
queue.Empty
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
ValueError: invalid literal for int() with base 10: '??'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Program Files\Python 3.5\lib\tkinter\__init__.py", line 1534, in __call__
args = self.subst(*args)
File "C:\Program Files\Python 3.5\lib\tkinter\__init__.py", line 1252, in _substitute
e.num = getint_event(b)
File "C:\Program Files\Python 3.5\lib\tkinter\__init__.py", line 1231, in getint_event
return int(s)
SystemError: result with error in PyObject_Call
如何重现:
打开程序,按播放然后按a。
我不知道有什么可能是错的,尽管我尝试在谷歌搜索。
我尝试添加打印但不会执行。
有谁知道我为什么会收到错误?
答案 0 :(得分:0)
问题是我使用的是3.5而不是3.4。切换版本有效。