Why I am getting AttributeError: "'NoneType' object has no attribute 'get'" with Python and Tkinkter?
from tkinter import *
app=Tk()
app.title(" BRAIN SYNCRONIZATION SOFTWARE ")
e1=Entry(app).pack()
t1=Text(ap开发者_JAVA技巧p).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)
This is the code I wrote, but I am repeatedly getting the following error when I press the input button:
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'
Why is it not writing the file?
t1=Text(app).pack()
should be
t1=Text(app)
t1.pack()
The Tkinkter pack()
method returns None, you can't run .get()
on it, but need to keep t1
referring to the text object itself.
I don't think that Entry(app).pack() will return anything. Do you mean e1=Entry(app); e1.pack()
?
精彩评论