my code is to display the gui then enter the text in it, after clicking the save text button, it should appear in file.txt.
I tried the save function
def save():
with open('test.txt', 'w') as f:
my_text = txt.toPlainText()
f.write(my_text)
This function is to read this code
txt = tk.Text(self, bd=3, exportselection=0, bg='WHITE', font='Helvetica',
padx=10, pady=10, height=5, width=30)
txt.pack()
The problem is that the text.txt file does not overwrite itself
The entire code looks like this
class PageNumber(tk.Frame):
def __init__(self, parent, controller):
def save():
with open('test.txt', 'w') as f:
my_text = txt.toPlainText()
f.write(my_text)
tk.Frame.__init__(self, parent)
self.controller = controller
self.configure()
txt = tk.Text(self, bd=3, exportselection=0, bg='WHITE', font='Helvetica',
padx=10, pady=10, height=5, width=30)
txt.pack()
btnsave = tk.Button(self, text="Zapisz wynik", padx=35, pady=10, fg="#ffffff", bg="#263942",
command=save)
btnsave.pack(fill="x")