Reputation: 25
I want what I get from function Sighnup and put it in 'Users.txt' and any tips in shortening TK code? I'm new to TK so any tips or tricks wpould be nice too!:) Oh and this is a program for an app my friend is making so I need it to work very well This is ~1/2 the code so i might need more help. Don't worry this is only one of the windows I have a login window too. I know there is two Sighnup functions but it works well so i'm keeping it that way.When I do the (ent.get()) it prints it on the shell not the txt but It made the txt file but won't write in it.
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()
Upvotes: 1
Views: 731
Reputation: 309919
Just opening a file doesn't make output go there, you need to write to it:
fout = open('Users.txt', 'w')
fout.write(ent.get())
...
Or better, use a context manager
with open('Users.txt', 'w') as fout:
fout.write(ent.get())
As far as suggestions to clean things up, I would use loops to create the widgets and lists to store them.
Upvotes: 1