簡體   English   中英

Python GUI寫入文件

[英]Python GUI writing to a file

我在嘗試使此功能正常工作時遇到問題。 我需要它寫入包含“ 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)

但是,當我使用此功能時,會出錯:

“” the_file.write(“名字:”,+ first)TypeError:一元錯誤的操作數類型+:'str'“

如果我擺脫了("First Name: ", +) ,那么它將把輸入字段寫入文本文件,無論其值是多少。

您的語法有誤。
它應該是:

the_file.write("First Name: " + first)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM