如何使用tkinter写入txt文档
How do I use tkinter to write into a txt document
到目前为止我们有很多代码,但我们找不到任何东西来记录信息并将其以包含所有类别的收据样式发送到 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)
学习python文件操作。我会推荐你访问这个网站,以便清楚地了解。
https://www.google.com/amp/s/www.geeksforgeeks.org/file-handling-python/amp/
到目前为止我们有很多代码,但我们找不到任何东西来记录信息并将其以包含所有类别的收据样式发送到 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)
学习python文件操作。我会推荐你访问这个网站,以便清楚地了解。
https://www.google.com/amp/s/www.geeksforgeeks.org/file-handling-python/amp/