[英]How to insert into tkinter Text widget
I'm trying to insert a txt file read variable into the tkinter Text widget, but, I'm having this error: _tkinter.TclError: bad window path name ".!toplevel"
我正在尝试将一个 txt 文件读取变量插入到 tkinter 文本小部件中,但是,我遇到了这个错误:
_tkinter.TclError: bad window path name ".!toplevel"
Check out my code:看看我的代码:
textInfo = tk.Text(accountPopup, width=40, height=10, font=("Helvetica", 12))
textInfo.pack(pady=20)
path = './Contas/Info/'+txtName+'.txt'
textFile = open(path , 'r')
readedText = textFile.read()
finalRead = str(readedText)
textInfo.insert(tk.END, finalRead)
It should be tk.END
and not END
simply because your import is import tkinter as tk
, so you should suffix END
with tk
.它应该是
tk.END
而不是END
仅仅是因为您的导入是import tkinter as tk
,所以您应该在END
后缀tk
。 Also you could say 'end'
instead of tk.END
.你也可以说
'end'
而不是tk.END
。
So to conclude:所以总结一下:
tk.END #import tkinter as tk
END #from tkinter import *
'end' #you can use this with any of the above type of imports
Hope this cleared your error, do let me know if any more doubts or errors.希望这清除了您的错误,如果有任何疑问或错误,请告诉我。
Cheers干杯
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.