我如何使用tkinter写入txt文档
到目前为止,我们有很多代码,但是我们找不到任何可以记录信息的内容,并以所有类别的方式将其发送到Reciept样式的TXT文档。如果有解决方案,我们找不到 这是我们代码的片段
#second window - rory
def new1():
root = Tk( )
root.config(bg=("#967117"))
root.geometry( '1100x600+100+100') #where the box will be on the screen
root.title("CheckOut")
root.resizable (width=False, height=False)
# address - rory
Label (root, text = "Address:").place(relx = 0.3 , rely = 0.5)
Label (root, text = "City:").place(relx = 0.3 , rely = 0.3)
Label (root, text = "Province/Territory:").place(relx = 0.3 , rely = 0.1)
Label (root, text = "Postal Code:").place(relx = 0.3 , rely = 0.7)
Label (root, text = "Phone Number:").place(relx = 0.3 , rely = 0.9)
depot7 = StringVar()
depot7.set(None)
OptionMenu (root, depot7, "British Columbia", "Alberta", "Saskatchewan", "Manitoba","Ontario","Yukon","Northwest Territories","Nunavut","Prince Edward Island","New Brunswick","Quebec","Nova Scotia","Newfoundland and Labrador").place(relx = 0.41 , rely = 0.09)
address1 = Entry(root, width = 30).place(relx = 0.34 , rely = 0.3)
address2 = Entry(root, width = 30).place(relx = 0.36 , rely = 0.5)
address3 = Entry(root, width = 14).place(relx = 0.38 , rely = 0.7)
pn = Entry(root, width = 18).place(relx = 0.39 , rely = 0.9)
#payment - rory
depot11 = StringVar()
depot11.set(None)
Label (root, text = "Type of Payment:").place(relx = 0.65 , rely = 0.1)
OptionMenu (root, depot11, "VISA", "MASTERCARD", "AMERICAN EXPRESS", "DISCOVER").place(relx = 0.75 , rely = 0.09)
Label (root, text = "Name On Card:").place(relx = 0.65 , rely = 0.3)
Label (root, text = "Card Number:").place(relx = 0.65 , rely = 0.5)
Label (root, text = "Expire Date (MM/YY):").place(relx = 0.65 , rely = 0.7)
Label (root, text = "CVV:").place(relx = 0.65 , rely = 0.9)
pay1 = Entry(root, width = 30).place(relx = 0.74 , rely = 0.3)
pay2 = Entry(root, width = 30).place(relx = 0.73 , rely = 0.5)
pay3 = Entry(root, width = 6).place(relx = 0.77 , rely = 0.7)
pay4 = Entry(root, width = 6).place(relx = 0.69 , rely = 0.9)
title = Label(root, text = "Cart", font = 40).place(relx = 0.14 , rely = 0.06)
cart1 = tk.Text(root, width = 30, height = 28, state='disabled').place(relx = 0.05, rely = 0.1)
def dad():
fileD = open("qqqq.txt", "a")
fileD.write("Address:\n")
fileD.write("%s\n" % address1.get())
fileD.write("City:\n")
fileD.write("%s\n" % address2.get())
fileD.write("Province/Territory:\n")
fileD.write("%s\n" % address3.get())
fileD.write("Postal Code:\n")
fileD.write("%s\n" % pn.get())
Button(root, bg ="hot pink", text = "Add To Cart", font = 80, borderwidth = 10, relief= "ridge", command = dad).place(relx = 0.2 , rely = 0.2)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
了解Python文件操作。我建议您访问该网站以了解。
Learn python file operation. I will recommend you to visit this website for a clear understanding.
https://www.google.com/amp/s/www.geeksforgeeks.org/file-handling-python/amp/