[英]Python GUI writing to a file
I am have a problem trying to get this function to work properly. 我在尝试使此功能正常工作时遇到问题。 I need it to write to a text file that includes "First Name: " , then add the input from the entry field at the end of "First Name: ". 我需要它写入包含“ First Name:”的文本文件,然后在“ First Name:”末尾从输入字段中添加输入。
def _NameEntry(self):
open("Results.txt", "w").close()
first = self._firstNameEntry.get()
with open("../Results.txt", "a") as the_file:
the_file.write("First Name: ", + first)
But when I use this function it errors this: 但是,当我使用此功能时,会出错:
"the_file.write("First Name: ", + first) TypeError: bad operand type for unary +: 'str'" “” the_file.write(“名字:”,+ first)TypeError:一元错误的操作数类型+:'str'“
If I get rid of the ("First Name: ", +)
, then it will write the entry field to the text file, whatever the value is. 如果我摆脱了("First Name: ", +)
,那么它将把输入字段写入文本文件,无论其值是多少。
You have an error in your Syntax. 您的语法有误。
It should be: 它应该是:
the_file.write("First Name: " + first)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.