-1

i want to save some information in a csv file. The file is supposed to contain a message from a user, the date and time and his or her name, all in one line. How would i go about making a GUI with Tkinter so a user can input that information and save it to a CSV file

Any help would be appreciated.

I tried looking for different solutions online but neither of which really helped me.

Danxs
  • 11
  • 3
  • Your first step is to create a GUI that takes input from the user. Start there: https://stackoverflow.com/questions/14824163/how-to-get-the-input-from-the-tkinter-text-widget – ScottC Nov 06 '22 at 13:35
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Nov 07 '22 at 06:36

1 Answers1

0

To start off with tkinter you need to create a window by doing

window = tkinter.Tk()

Then you need to create some text boxes to input the info with text above to say what they are

Message_Text = tkinter.Label(window, text="Input a message", font=("Calibri", 50), bg="#a9a9a9", fg="#ffffff")
Message = tkinter.Entry(window, font=("Calibri", 50), bg="#a9a9a9", fg="ffffff")
Date_Label = tkinter.Label(window, text="Input the date and time", font=("Calibri", 50), bg="#a9a9a9", fg="#ffffff")
Date = tkinter.Entry(window, font=("Calibri", 50), bg="#a9a9a9", fg="ffffff")
Name_label = tkinter.Label(window, text="Input your name", font=("Calibri", 50), bg="#a9a9a9", fg="#ffffff")
Name = tkinter.Entry(window, font=("Calibri", 50), bg="#a9a9a9", fg="ffffff")

Then after that you need to create a function to get all of that data when the user presses a button but put this at the start

def get_data():
    Message_data = Message.get()
    Date_data = Date.get()
    Name_data = Name.get()
    File = open("file.txt", "w")
    File.write(Message_data + ", " + Date_data + ", " + Name_data)

Then create a button which we will link the function to

button = tkinter.Button(self.window, text="Submit", font=("Calibri", 50), command=get_data, bg="#a9a9a9", fg="#ffffff")

Pack all of the objects

Message_Text.pack()
Message.pack()
Date_Label.pack()
Date.pack()
Name_label.pack()
Name.pack()
button.pack()
window.mainloop()

and that should work

mx0
  • 6,445
  • 12
  • 49
  • 54