类型错误:grid_configure() 缺少 1 个必需的位置参数:'self'

类型错误:grid_configure() 缺少 1 个必需的位置参数:'self'

问题描述:

prompt = ">>"
from tkinter import *

root = Tk()
userName = Entry()
myLabel = Label(root, text="UserName")

userName.grid(row=0)
myLabel = Label.grid(row=0, column=1)
root.mainloop()

类型错误:grid_configure() 缺少 1 个必需的位置参数:'self'

TypeError: grid_configure() missing 1 required positional argument: 'self'

此说法不正确:

myLabel = Label.grid(row=0, column=1)

至少应该是这样的:

myLabel = Label().grid(row=0, column=1)

不过,如果你想让 mayLabel 成为 None 以外的任何东西,你需要使用两行:

Though, if you want mayLabel to be anything other than None you need to use two lines:

myLabel = Label()
myLabel.grid(row=0, column=1)

不过,如果您想使用 myLabel 之前的定义,也许您需要简单地省略 myLabel = Label(),因为这会创建一个新的空标签.

Though, if you want to use the previous definition of myLabel, maybe you need to simply omit myLabel = Label(), since that creates a new empty label.