使用代码输入在 pyqt 中保存文件

Saving a file in pyqt with inputs from code

input_example = QInputDialog.getText(self, "", "Please type your name here:") # this allows the users to enter their name

myfile = open(str(input_example) + ".txt","w") #this creates a new file with what the user has entered as the name of the file

myfile.write("Here is their score: " + str(self.points_Q11_L1) + "\n")  # this prints their score

myfile.close()

上面的代码要求输入用户名,当他们单击“确定”时,它会创建文件,并将文件命名为 ("Example Name", True)

有没有办法删除 true 使其不显示?

input_example[0] 放在您创建文件的位置,以便仅 select 字符串结果。