【问题标题】:AttributeError: 'NoneType' object has no attribute 'insert'AttributeError:“NoneType”对象没有属性“插入”
【发布时间】:2021-09-01 13:07:33
【问题描述】:
def gen_p():
    psmi = 5
    psma = 10
    ch_v = string.digits + string.ascii_letters + string.punctuation
    passc = "".join(choice(ch_v) for x in range(randint(psmi, psma)))
    passe.insert(0, passc)

当我想在我得到的 python 条目中显示响应时,python 代码有问题:

AttributeError: 'NoneType' 对象没有属性 'insert'

我正在查找代码中的错误,但找不到。

【问题讨论】:

  • passe 未定义!是清单吗?所以在你的 for 循环之前,你可能有 passe = []
  • Je ne peux pas car passe est une variable que j'ai attribué à une Entry
  • @Théophile 请使用英语。
  • 这告诉您passe 设置为None。你需要向我们展示你是如何定义passe的。

标签: python


【解决方案1】:

我在这里建立一个简单的项目:

from tkinter import *
import tkinter as tk
screen=Tk()
def ins(text):
    listbox.insert(0,text)
    listbox.place(x=30,y=10)
listbox=Listbox(screen)
ins("Hello")
screen.title("Simple Project")
screen.mainloop()

您收到此错误是因为在 place(),grid(),... 之后按钮、标签、...将变为 NoneType。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-01
    • 2021-12-26
    • 2019-07-23
    • 2018-05-13
    • 2020-09-07
    • 2017-05-03
    相关资源
    最近更新 更多