3
我就在這裏:http://effbot.org/zone/vroom.htm 並試圖了這一點:的Tkinter保存文本編輯器
filename = raw_input("Filename?")
editor = Text()
editor.pack(fill=Y, expand=1)
editor.config(font="Courier 12")
editor.focus_set()
mainloop()
#save
f = open(filename, "w")
text = str(editor.get(0.0,END))
try:
f.write(text.rstrip())
f.write("\n")
但是,我得到了一個錯誤:
TclError: invalid command name ".40632072L"
我怎樣才能解決這個問題呢? 我不喜歡面向對象的編程,所以我更喜歡一個命令式的解決方案(沒有任何class
關鍵字)。
哪一行產生該錯誤?請打印整個堆棧跟蹤。 – Brionius
另外,在將來,請發佈足夠完整的代碼來運行。這會引發一個明顯的'SyntaxError',讓'try'沒有'except'或'finally'。 (另外,作爲一個附註,你真的應該把'open/try/finally/close'轉換成'with open';你看到的這個例子很古老......) – abarnert
對不起,完整的代碼真的是多餘的。我會記得下次 – leonneo