我有以下代码:类型错误在__init __(),意外的说法蟒蛇
from tkinter import *
class Button:
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.printButton = Button(frame, text = "Print Message", command=self.printMessage)
self.printButton.pack(side = LEFT)
self.quitButton = Button(frame, text = "Quit", command = frame.quit)
self.quitButton.pack(side = LEFT)
def printMessage(self):
print(" WORKING!! ")
root = Tk()
b = Button(root)
root.mainloop()
似乎并没有哪个是错误的,无论如何......但是当我运行它,终端说:
Traceback (most recent call last):
File "class.py", line 23, in <module>
b = Button(root)
File "class.py", line 10, in __init__
self.printButton = Button(frame, text = "Print Message", command=self.printMessage)
TypeError: __init__() got an unexpected keyword argument 'command'
我根据tkinter教程编写了所有这些代码。在教程中,代码运行良好。任何帮助,将不胜感激。提前致谢!
你只是创建你自己的'Button'类的另一个实例。尝试将其重命名为“CustomButton”。 – zondo
许多Tkinter示例代码使用'from tkinter import *',但是您现在已经发现这是一个**糟糕的主意。 –
@ PM2Ring,每当我学习一些你提到的基础知识时,我的生活就会变得更有意义:P。非常感谢您的建议! –