0
我写了一个简单的报告程序,当完成时输出到文本文件。它工作正常,所以我决定以GUI形式复制程序。然而,当它将输入输出到一个文本文件时,输入的名字就是一串数字。无论选中哪个复选框,它也只打印到主日志。有人可以突出显示此程序所需的更改,以便将输入导出到未改变的txt文件,而不是数字串?非常感谢:用gui打印到txt python 2.7
from Tkinter import *
root = Tk()
one = Label(root, text = "welcome to maxwell's reporter program")
reporter_name = Entry(root)
charge_nurse = Entry(root)
label_1 = Label(root, text = "reporter's name")
label_2 = Label(root, text = "nurse in charge")
label_3 = Label(root, text = "please tick the type of concern")
capacity = Checkbutton(root, text="capacity")
speciality = Checkbutton(root, text="speciality")
ward = Checkbutton(root, text="ward")
transfer = Checkbutton(root, text="transfer")
staffing = Checkbutton(root, text="staffing")
equipement = Checkbutton(root, text="equipement")
other = Checkbutton(root, text="other")
concern_body_label = Label(root, text = "please state your concern below:")
concern_body = Text(root, height=6, width=60)
one.grid(columnspan=2)
label_1.grid(row=1, sticky=E)
label_2.grid(row=2, sticky=E)
reporter_name.grid(row=1, column=1, sticky=W)
charge_nurse.grid(row=2, column=1, sticky=W)
label_3.grid(columnspan=2)
capacity.grid(row=4, sticky=W)
speciality.grid(row=5, sticky=W)
ward.grid(row=6, sticky=W)
transfer.grid(row=7, sticky=W)
staffing.grid(row=8, sticky=W)
equipement.grid(row=9, sticky=W)
other.grid(row=10, sticky=W)
concern_body_label.grid(row=11, sticky=W)
concern_body.grid(row=12, columnspan=2)
from datetime import datetime
now = datetime.now()
date = '%s/%s/%s' % (now.day, now.month, now.year)
time = '%s:%s' % (now.hour, now.minute)
concern_body = str(concern_body)
reporter_name = str(reporter_name)
charge_nurse = str(charge_nurse)
def main_function():
main = [date, time, "reported by: " + reporter_name.get("1.0",END), "nurse in charge: " + charge_nurse.get("1.0",END), "statement: " + concern_body.get("1.0",END)]
main = str(main)
if capacity == True:
appendFile = open("Capacity.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
if speciality == True:
appendFile = open("Speciality.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
if ward == True:
appendFile = open("Ward.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
if transfer == True:
appendFile = open("Transfer.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
if staffing == True:
appendFile = open("Staffing.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
if equipement == True:
appendFile = open("Equipement.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
if other == True:
appendFile = open("Other.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
appendFile = open("Main_log.txt","a")
appendFile.write("\n\n" + str(main))
appendFile.close()
submit_button = Button(root, text="submit concern", command = main_function)
submit_button.grid(row=13)
root.mainloop()
请提供[MCVE](http://stackoverflow.com/help/mcve),其中包含输入/电流输出/期望输出的示例。 – Mel
我已经拍摄了我的代码的屏幕打印。它可以通过蓝色链接获得:我的代码在这里。对不起,如果它不是传统的,这是我第一次使用这个网站 – max89
请编辑您的文章,并使用代码标签包含代码,请参阅此处的说明http://meta.stackoverflow.com/questions/251361/how-do- i-format-my-code-blocks – user2682863