Python Tkinter(初级)

时间:2017-07-04 10:48:00

标签: python user-interface tkinter

我需要一些帮助!

import tkinter as tk


class CountVisitors:
    def __int__(self, master):
        self.master = master

        self.button1 = tk.Button(self.master, text="Count", command=self.counting)

        self.button1.pack(side=tk.LEFT)

        self.button_click = 0

    def counting(self):
        self.button_click += 1
        print(self.button_click)


def main():
    root = tk.Tk()
    CountVisitors(root)
    root.mainloop()


if __name__ == "__main__":
    main()

当我尝试运行此代码时,它会提示我一条错误消息:

Traceback (most recent call last): 
    File "C:/Users/Anson/PycharmProjects/improvement/improvement.py", line 26, in <module> main() 
    File "C:/Users/Anson/PycharmProjects/improvement/improvement.py", line 21, in main CountVisitors(root) 
    TypeError: object() takes no parameters

这是什么意思?

1 个答案:

答案 0 :(得分:2)

__init__拼写错误(错过了&#39; i&#39;)。

更改行:

def __int__(self, master):

为:

def __init__(self, master):