[英]Python Open File Button
I am having trouble, trying to get my open button to open a text file. 我遇到了麻烦,试图让我的打开按钮打开文本文件。 I want it to open the text file into the not pad, when I click the open button.
当我单击打开按钮时,我希望它将文本文件打开到not pad中。 If some one could help me or tell me what I am doing wrong, I would appreciate it.
如果有人可以帮助我或告诉我我做错了什么,我将不胜感激。
def _open(self):
open("../Address.txt","r").close()
with open("../Address.txt", "a") as file:
self._outputArea.insert("1.0", file.read)
file.read()
with
line. with
行。 file
as a variable name, it's also a type. file
用作变量名,它也是一种类型。 read
. read
。 'a'
is a flag for appending a file, use 'r'
(for read) instead. 'a'
是用于附加文件的标志,请改用'r'
(供读取)。 Try something like: 尝试类似:
def _open(self):
with open("../Address.txt", "r") as the_file:
self._outputArea.insert("1.0", the_file.read())
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.