【问题标题】:'NoneType' object has no attribute 'get' [duplicate]“NoneType”对象没有属性“get”[重复]
【发布时间】:2019-05-21 11:15:58
【问题描述】:

我想用用户的输入在 tkinter 中制作一个计算器。 但是,我不能这样做,因为它有一个“NoneType”对象错误。

A = Label(janela, text = "A=",)
A.place( x = 220, y = 70)
a = StringVar
caixa_de_escrita_a = Entry(janela, textvariable = a, width = 25, bg = 
"lightgreen").place(x=250, y= 70)
B = Label(janela, text = "B=")
B.place(x=220 , y = 85) 
b = StringVar
caixa_de_escrita_b = Entry(janela, textvariable = b, width = 25, bg = 
"lightgreen").place(x=250, y =``85)

 c = int(caixa_de_escrita_a.get())
 d = int(caixa_de_escrita_b.get())

错误:

c = int(caixa_de_escrita_a.get())
AttributeError: 'NoneType' object has no attribute 'get'

【问题讨论】:

  • 看起来place 返回None。也许您打算将caixa 变量设置为Entry 对象,而不是place 的返回值。

标签: python python-3.x tkinter


【解决方案1】:

看起来place 返回None。也许您打算将caixa 变量设置为Entry 对象,而不是place 的返回值。

像这样:

caixa_de_escrita_a = Entry(janela, textvariable=a, width=25, bg="lightgreen")
caixa_de_escrita_a.place(x=250, y=70)
... 
caixa_de_escrita_b = Entry(janela, textvariable=b, width=25, bg="lightgreen")
caixa_de_escrita_b.place(x=250, y=85)

【讨论】:

    猜你喜欢
    • 2016-09-20
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-02
    • 1970-01-01
    • 1970-01-01
    • 2022-08-10
    • 1970-01-01
    相关资源
    最近更新 更多