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

时间:2015-12-29 14:06:33

标签: python pyqt pyqt4

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)

有没有办法删除它,以便它不会显示?

1 个答案:

答案 0 :(得分:1)

input_example[0]放在您创建文件的位置,只选择字符串结果。