gpt4 book ai didi

python - 乒乓球游戏两名玩家 tkinter 错误

转载 作者:太空宇宙 更新时间:2023-11-03 18:38:08 25 4
gpt4 key购买 nike

我尝试执行这段代码:

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 作为变量传入

def main(cls):  

然后你就可以像函数一样使用它

game = cls(tkFont.Font(family='Book Antiqua', size=15, weight='bold'), 5, 100,background='black', width=640, height=480)

关于python - 乒乓球游戏两名玩家 tkinter 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21150220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com