2011-06-12 56 views
2
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) 

这是我写的代码,但我反复得到以下错误,当我按下输入按钮:为什么我得到AttributeError:''NoneType'对象没有Python和Tkinkter的'get''属性?

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' 

为什么不写文件?

+1

Python位?哎哟! – alex 2011-06-12 03:29:53

+0

@alex :)很好......这就是为什么我在这里! – Vonn 2011-06-12 03:31:41

回答

9
t1=Text(app).pack() 

应该

t1=Text(app) 
t1.pack() 

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

+0

它工作了!!!!! – Vonn 2011-06-12 03:49:23

+0

它工作!太感谢了!!! :) – Vonn 2011-06-12 03:50:32

+3

@Vonn:欢迎来到StackOverflow! “它的工作!!!感谢百万!!! :)”是最好的表达“[通过点击答案左边的复选框大纲](http://stackoverflow.com/faq#howtoask)” – Johnsyweb 2011-06-12 05:39:22

0

我不认为Entry(app).pack()会返回任何东西。你的意思是e1=Entry(app); e1.pack()

相关问题