我想从函数 Sighnup 中得到什么并将其放入“Users.txt”以及缩短 TK 代码的任何提示?我是 TK 新手,所以任何提示或技巧也很不错!:) 哦,这是我朋友正在制作的应用程序的程序,所以我需要它很好地工作这是〜1/2的代码,所以我可能会需要更多帮助。别担心,这只是我也有登录窗口的窗口之一。我知道有两个 Sighnup 函数,但它运行良好,所以我保持这种方式。当我执行 (ent.get()) 时,它在 shell 上打印它而不是 txt,但它生成了 txt 文件但不会写在里面。
import tkinter
def Sighnup():
window2 = tkinter. Tk()
def Quit2 ():
window2.destroy()
def Sighnup():
open ('Users.txt','w')
(ent.get())
(ent2.get())
(ent3.get())
(ent4.get())
(ent5.get())
window2.destroy()
window2.geometry("195x135")
window2.title("Sighnup")
window2.wm_iconbitmap('favicon.ico')
lbl= tkinter.Label(window2, text="First Name:")
lbl2= tkinter.Label(window2, text="Last Name:")
lbl3= tkinter.Label(window2, text="Email:")
lbl4= tkinter.Label(window2, text="Username:")
lbl5= tkinter.Label(window2, text="Password:")
ent= tkinter.Entry(window2)
ent2= tkinter.Entry(window2)
ent3= tkinter.Entry(window2)
ent4= tkinter.Entry(window2)
ent5= tkinter.Entry(window2)
btn= tkinter.Button(window2, text="Submit", command=Sighnup)
btn2= tkinter.Button(window2, text="Quit", command=Quit2)
lbl.grid(row=0, column=0)
ent.grid(row=0, column=1)
lbl2.grid(row=1, column=0)
ent2.grid(row=1, column=1)
lbl3.grid(row=2, column=0)
ent3.grid(row=2, column=1)
lbl4.grid(row=3, column=0)
ent4.grid(row=3, column=1)
lbl5.grid(row=4, column=0)
ent5.grid(row=4, column=1)
btn2.grid(row=5, column=1)
btn.grid(row=5, column=0)
window2.mainloop()