类型错误:grid_configure() 缺少 1 个必需的位置参数:'self' [英] TypeError: grid_configure() missing 1 required positional argument: 'self'

查看:31
本文介绍了类型错误: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.

这篇关于类型错误:grid_configure() 缺少 1 个必需的位置参数:'self'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆