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

标签 python python-2.7 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 作为变量传入

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/

相关文章:

Python:从第二个列表开始删除一组列表的每个列表中的第一项

python - 带条件的最短路径图搜索

python - 如何导入自己的模块进行模拟? (导入错误 : no module named my_module!)

python - django-admin startproject 不能在 OS X 上使用 python3

python-2.7 - 尝试安装pycurl时出错

Python如何使用数据框应用方法查找列的平均值

python - 根据重复的单词拆分现有列表

Python 3 保存按钮

python - 在 Tkinter 中使用 askdirectory() 选择文件夹时显示所有文件

python - 如何在 python 中以有理数形式打印/显示表达式