Python Forum
[Tkinter] Trying to add data into a shelf from a submit button
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Trying to add data into a shelf from a submit button
#2
To get the input from shelve into the GUI when it is created you could change
        #open text file
        student_scores = shelve.open('student_name', 'c')
         
        #Display menue here here
        self.student_name = StringVar()
to
        #open text file
        with shelve.open('student_name', 'c') as db:
            student_name = db["Student Name"]
        
        #Display menue here here
        self.student_name = StringVar()
        self.student_name.set(student_name)
This will open the file and automatically close it after the value has been read into student_name
Then the StringVar is set to the value from student_name

The following close is not needed as it automatically closed above
        #close test file
        student_scores.close()
In the button handler event you didn't do anything with shelve, that is why nothing happened
    #function to set student names
    def set_names(self):
        student_name = [self.student_name.get()]
        print("submitt function pressed")
You can change it to
    #function to set student names
    def set_names(self):
        student_name = self.student_name.get()
        print("submitt function pressed")
        with shelve.open('student_name', 'c') as db:
            db["Student Name"] = student_name

Also, the entry needs to be told to use the stringvar
Change
#text box
self.input = Entry(self)
self.input.grid(row = 7, column = 1)
to
#text box
self.input = Entry(self,textvariable=self.student_name)
self.input.grid(row = 7, column = 1)
Reply


Messages In This Thread
RE: Trying to add data into a shelf from a submit button - by Yoriz - Dec-18-2022, 08:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Can't get tkinter button to change color based on changes in data dford 4 3,515 Feb-13-2022, 01:57 PM
Last Post: dford
  Button to add data to database and listbox SalsaBeanDip 1 2,946 Dec-06-2020, 10:13 PM
Last Post: Larz60+
  Database Submit Entry Syntax Error Melford 27 8,101 Jan-27-2020, 04:20 PM
Last Post: Denni
  Problem with Submit button Tkinter Reldaing 2 3,734 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa
  [PyQt] Pyqt5: How do you make a button that adds new row with data to a Qtablewidget YoshikageKira 6 7,187 Jan-02-2020, 04:32 PM
Last Post: Denni
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,088 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp

Forum Jump:

User Panel Messages

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