I want to save the input form the entry box into .txt
files and it works on the first code and not the second code, but what I need to use is the second code.
Code 1:
import tkinter as tk
def f():
def save():
a = t.get()
f = open((a + '.txt'), 'w')
f.write(a)
f.close()
return
top = tk.Tk()
t = tk.StringVar()
e = tk.Entry(top, textvariable = t).pack()
b = tk.Button(top, text = 'Save as a file', command = save).pack()
top.mainloop()
f()
Code 2:
import tkinter as tk
root = tk.Tk()
def f():
def save():
a = t.get()
f = open((a + '.txt'), 'w')
f.write(a)
f.close()
return
top = tk.Tk()
t = tk.StringVar()
e = tk.Entry(top, textvariable = t).pack()
b = tk.Button(top, text = 'Save as a file', command = save).pack()
top.mainloop()
button = tk.Button(root, text="Button",command=f).pack()
root.mainloop()