【发布时间】:2021-10-05 18:54:16
【问题描述】:
我正在尝试学习 Python 中的类。
我用 tkinter 写了一点代码
from tkinter import *
class window():
def __init__(self, size, title, ):
self.size = size
self.title = title
window = Tk()
window.geometry(self.size)
window.title(self.title)
print('a window has been created')
window.mainloop()
def button(self, window, text, x, y):
self.window = window
self.text = text
self.x = x
self.y = y
button = Button(window, text=text).place(x=str(x), y=str(y))
但我收到错误消息:
self.tk = master.tk
AttributeError: 'window' object has no attribute 'tk'
【问题讨论】:
-
类的定义方式很奇怪。你怎么称呼它?
-
您需要包含您的完整代码,公司。生成错误消息的行来自哪里?
-
root = window('640x640', 'Root Window')root.button(root, 'test', "0", "0")