NoneType 对象没有属性获取
NoneType object has no attribute get
我在使用 tkinter 时遇到了一些麻烦
问题是没有可以与小部件文本一起使用的方法。这是我的代码
from tkinter import *
root = Tk()
tex = Text(root, width = 50, height = 10, bd = 2).pack()
tex.get(1.0, END)
root.mainloop()
它returns错误:
AttributeError: 'NoneType' object has no attribute 'get'
这让我很生气!我对任何文本方法都有这样的问题
您将"pack"的return值保存在"tex"中,即None。
这是正确的:
tex = Text(root, width = 50, height = 10, bd = 2)
tex.pack()
我在使用 tkinter 时遇到了一些麻烦 问题是没有可以与小部件文本一起使用的方法。这是我的代码
from tkinter import *
root = Tk()
tex = Text(root, width = 50, height = 10, bd = 2).pack()
tex.get(1.0, END)
root.mainloop()
它returns错误:
AttributeError: 'NoneType' object has no attribute 'get'
这让我很生气!我对任何文本方法都有这样的问题
您将"pack"的return值保存在"tex"中,即None。 这是正确的:
tex = Text(root, width = 50, height = 10, bd = 2)
tex.pack()