我試圖執行此代碼:乒乓球比賽兩名球員Tkinter的錯誤
import Tkinter as tk
import tkFont
import functools
import math
import random
import time
class Pong(tk.Canvas):
DEFAULTS = dict(width=640, height=480,background='black',highlightthickness=0)
def main(cls):
root = tk.Tk()
root.title('Pong')
root.resizable(False, False)
root.bind_all('<Escape>', lambda event: root.destroy())
game = cls(tkFont.Font(family='Book Antiqua', size=15, weight='bold'), 5, 100,background='black', width=640, height=480)
game.grid()
root.mainloop()
,但我有這些錯誤:
Traceback (most recent call last):
line 413, in <module>
pong.main()
, line 17, in main
game = cls(tkFont.Font(family='Book Antiqua', size=15, weight='bold'), 5, 100,background='black', width=640, height=480)
AttributeError: Pong instance has no __call__ method
什麼是CLS您傳遞? – aIKid
你可以告訴我們你在哪裏調用'pong.main()',並在你分配'pong'之前的一段時間? – poke
如果__name__ == '__main__': 乒乓=傍() Pong.main() – user3200290