我正在尝试创建一个程序,我可以输入工作注释并输出到文本文件并复制到剪贴板以发布到注释模板中。
当我运行此程序时,文本框输入(entry4)将以单行复制到剪贴板。即。(example example example)
我希望将其复制到剪贴板中
Line1
Line2
Line3
这是程序代码。
from tkinter import *
import pyperclip
import datetime
root = Tk()
root.wm_title("Hector's Notes Program")
root.iconbitmap("TDS.ico")
time = str(datetime.datetime.now().strftime("%A, %dth %B %Y %I:%M%p"))
nl = "\r\n"
def printInfo():
file = open("C:\\Users\\Hector\\Desktop\\Test.txt", "a")
file.write(nl + time + nl)
file.write(q1 + nl)
file.write(entry1.get() + nl)
file.write(q2 + nl)
file.write(entry2.get() + nl)
file.write(q3 + nl)
file.write(entry3.get() + nl)
file.write(q4 + nl)
file.write(entry4.get("1.0", 'end-1c') + nl)
file.write(q5 + nl)
file.write(entry5.get() + nl)
file.write(q6 + nl)
file.write(entry6.get() + nl)
file.write(nl)
file.close()
results = q1 + "\r\n" + entry1.get() + "\r\n" + q2 + "\r\n" + entry2.get() + "\r\n" + q3 + "\r\n" + entry3.get() + "\r\n" + q4 + "\r\n" + entry4.get("1.0", 'end-1c') + "\r\n" + q5 + "\r\n" + entry5.get() + "\r\n" + q6 + "\r\n" + entry6.get()
print(results)
pyperclip.copy(results)
q1 = "Customer Name:"
q2 = "Contact Number:"
q3 = "Customer Reporting:"
q4 = "Troubleshooting done:"
q5 = "Is the issue resolved / Next step?"
q6 = "UTS Ticket #"
label1 = Label(root, text=q1)
label2 = Label(root, text=q2)
label3 = Label(root, text=q3)
label4 = Label(root, text=q4)
label5 = Label(root, text=q5)
label6 = Label(root, text=q6)
entry1 = Entry(root)
entry2 = Entry(root)
entry3 = Entry(root)
entry4 = Text(root, width=40, height=10)
entry5 = Entry(root)
entry6 = Entry(root)
entry1.focus_set()
label1.grid(row=0, column=0, sticky=E)
label2.grid(row=1, column=0, sticky=E)
label3.grid(row=2, column=0, sticky=E)
label4.grid(row=3, columnspan=2, sticky=S)
label5.grid(row=5, column=0, sticky=E)
label6.grid(row=6, column=0, sticky=E)
entry1.grid(row=0, column=1)
entry2.grid(row=1, column=1)
entry3.grid(row=2, column=1)
entry4.grid(row=4, columnspan=2)
entry5.grid(row=5, column=1)
entry6.grid(row=6, column=1)
button1 = Button(root, text="Print Notes", command=printInfo)
button1.grid(row=7, columnspan=2)
root.mainloop()
感谢您提供任何建议。