我正在尝试为我的python项目创建自定义标签,但是当我运行代码时,IDE向我发送错误。
这是我的类,在其中创建带有自定义标签的函数:
from tkinter import *
class designtools:
def create_label(window, name_of_label, row, column):
label = Label(window, name_of_label)
label.grid(row = row, column = column)
return label
这是方法的调用:
label_location = designtools.create_label(window, "location", 0, 0)
这是IDE的输出
Traceback (most recent call last):
File "C:\Users\Admin\Desktop\programma orari\programma_orari.py", line 19, in <module>
label_location = designtools.create_label(window, "location", 0, 0)
File "C:\Users\Admin\Desktop\programma orari\designtools.py", line 6, in create_label
label = Label(window, name_of_label)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 3143, in __init__
Widget.__init__(self, master, 'label', cnf, kw)
File "C:\Users\Admin\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 2564, in __init__
classes = [(k, v) for k, v in cnf.items() if isinstance(k, type)]
AttributeError: 'str' object has no attribute 'items'
感谢帮助。
答案 0 :(得分:0)
我假设sequelize.define('oAuthAccessTokens', {
id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true
},
createdAt: Sequelize.DATE,
updatedAt: Sequelize.DATE,
accessToken: { type: Sequelize.STRING(256), allowNull: false },
expires: { type: Sequelize.DATE, allowNull: false },
scope: Sequelize.STRING(255),
clientId: {
type: Sequelize.STRING(80),
allowNull: false,
onDelete: "cascade",
references: {
model: 'oAuthClients',
key: "clientId",
}
},
userId: {
type: Sequelize.INTEGER,
onDelete: "cascade",
allowNull: false,
references: {
model: 'oAuthUsers',
key: "id"
}
}
});
是您想要在标签上显示的文本。
您可以这样实现:
name_of_label
然后以这种方式调用它:
import tkinter as tk
class designtools:
@staticmethod
def create_label(window, text, row, column):
label = tk.Label(master=window, text=text)
label.grid(row = row, column = column)
return label
此标签应显示我的文字。