gpt4 book ai didi

python - 为什么我收到 AttributeError : "' NoneType' object has no attribute 'get' "with Python and Tkinkter?

转载 作者:行者123 更新时间:2023-11-28 20:10:45 25 4
gpt4 key购买 nike

from tkinter import *

app=Tk()

app.title(" BRAIN SYNCRONIZATION SOFTWARE ")

e1=Entry(app).pack()
t1=Text(app).pack()

def InputFun():
file=open("acad.txt","a")
file.write("%s;%s"%(t1.get("0.1",END),e1.get()))
file.close()
b1=Button(app,text="INPUT",command=InputFun,height=3,width=4).pack(side=LEFT,padx=30,pady=30)

这是我写的代码,但是当我按下输入按钮时,我反复出现以下错误:

Exception in Tkinter callback
Traceback (most recent call last):
File "C:\Python31\lib\tkinter\__init__.py", line 1399, in __call__
return self.func(*args)
File "C:\Users\vonn\Desktop\brain syncronization.py", line 15, in InputFun
file.write("%s"%t1.get("0.1",END))
AttributeError: 'NoneType' object has no attribute 'get'

为什么不写入文件?

最佳答案

t1=Text(app).pack()

应该是

t1=Text(app)
t1.pack()

Tkinkter pack() 方法返回 None,你不能在上面运行 .get(),但需要保持 t1引用文本对象本身。

关于python - 为什么我收到 AttributeError : "' NoneType' object has no attribute 'get' "with Python and Tkinkter?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6319942/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com