I have a variable which contains a string that I want to write in a .txt file using python. But I don't know how to do so. e1
is the variable which contains the string.
from tkinter import *
root = Tk()
root.title("records manager")
root.geometry("600x200")
label0 = Label(root, text="")
label0.pack()
label1 = Label(root, text="Welcome to records manager (づ。◕‿‿◕。)づ", font=("ariel bold", 20))
label1.pack()
leftframe = Frame(root, padx="20", pady="20")
leftframe.pack(side=LEFT)
rightframe = Frame(root, padx="20", pady="20")
rightframe.pack(side=RIGHT)
def add():
patients = open("Patients.txt", "a")
e1 = Entry1.get()
patients.write(e1 + "\n")
patients.close()
New = Label(leftframe, text="New Patients", font=("ariel bold", 12))
New.grid(row=0)
Entry1 = Entry(leftframe, width=40, border=5)
Entry1.grid(row=0, column=1)
button1 = Button(rightframe, width=20, command=add(), text="Add")
button1.grid(row=0, column=0)
root.mainloop()