2016-10-12 22 views
-1

私はtkinterを通してユーザからテキストを取り出し、テキストファイルに入れようとしています。私はテキストファイルに何かを書くプログラムを持っていますが、それはユーザーが入力するものではなく、むしろ乱数と文字の束です。ここに私のコードです。Tkinterのpythonからテキストファイルに書き込む

import Tkinter 
from Tkinter import * 

def writeFile (textObj): 
    file = open("alaskaQuestion.txt",'a+') 
    file.write(textFile2) 
    textObj.insert(INSERT, file.read()) 
    file.close() 

gui = Tkinter.Tk() 


textFile2 = Tkinter.Entry(gui) 
textFile2.grid(row=9, column=1) 

textFile2 = str(textFile2) 

buttonWrite = Tkinter.Button(gui, text = "Write To File", command = lambda: writeFile(textFile)).grid(row=8, column=1) 

gui.mainloop() 
+0

ウィジェットの_contents_ではなく、ウィジェットを作成しようとしています。ウィジェットからコンテンツを取得することは、たぶんすべてのtkinterチュートリアルとドキュメンテーションサイトで説明されています。 –

答えて

0

エントリの内容を取得するには、file.write(textFile2).get()を使用します。

関連する問題