Python Forum
How to save record
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to save record
#1
How to save variable value entered by user from GUI

I made this program How to modified program to store details

python 3 raspbain os

from tkinter import *    
top = Tk()

NameLabel= Label(top, text="Name", relief=RIDGE,width=10, height= 5)
NameLabel.grid(row=2, column=0)

NameEntry = Entry(top)
NameEntry.grid(row=2, column=1)

Button1 = Button(text="Submit", relief=RIDGE,width=10, height= 5)
Button1.grid(row=2, column=3)

AgeLabel = Label(top, text="Age", relief=RIDGE,width=10, height= 5)
AgeLabel.grid(row=3, column=0)

AgeEntry = Entry(top)
AgeEntry.grid(row=3, column=1)

Button2 = Button(text="Submit", relief=RIDGE,width=10, height= 5)
Button2.grid(row=3, column=3)

mainloop()
Reply
#2
Add event handlers to your buttons, and then save state in the event handlers. Something like:
def name_submit_handler():
    # save state here
    print("Button was clicked!")

# and then later...
Button1 = Button(text="Submit", command=name_submit_handler, relief=RIDGE, width=10, height=5)
Button1.grid(row=2, column=3)
Reply
#3
I think he or she means how do i save the input information. well you could save it a thousand different ways, write to text file.
save it in a data base with pickle or shelve, or email it to a friend, here's how to save it to a basic txt file

from tkinter import *    
top = Tk()
def getinfo():
    ne= NameEntry.get() #get name
    yr= AgeEntry.get()
    scm= open('secretclubmembers.txt', 'a') #create and append
    scm.write('Member %s Age: %s'% (ne,yr))
    scm.close()
    print('info was saved: {0},{1}'.format(ne,yr))
    #clear the entry field
    #clearinfo()
     
         
NameLabel= Label(top, text="Name", relief=RIDGE,width=10, height= 5)
NameLabel.grid(row=2, column=0)
 
NameEntry = Entry(top)
NameEntry.grid(row=2, column=1)
 
Button1 = Button(text="Submit",command=getinfo,
                 relief=RIDGE,width=10, height= 5)
Button1.grid(row=2, column=3)
 
AgeLabel = Label(top, text="Age", relief=RIDGE,width=10, height= 5)
AgeLabel.grid(row=3, column=0)
 
AgeEntry = Entry(top)
AgeEntry.grid(row=3, column=1)
 

 
mainloop()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] [split] I want to add a code to the "Save" button to save the data entered LOO 1 1,973 Jan-23-2023, 05:31 PM
Last Post: deanhystad
  [Tkinter] sqlite3 check last record rwahdan 1 1,885 Jul-07-2021, 11:40 AM
Last Post: Larz60+
  Save image from Clipboard Linux / save Pixbuf format M_Schneider 1 2,854 May-04-2018, 04:38 PM
Last Post: woooee

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020