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
#1
I am new to Python and trying to run a small program that takes a input from a text field and submit it into a shelf.
The code runs with no errors but does not input any data
Thanks for any direction you may give
# Sample Solution

from tkinter import *
import shelve

class MyFrame (Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.geometry("600x600")
        self.master.title("Student Scores")
        self.grid()
  
        #open text file
        student_scores = shelve.open('student_name', 'c')
        
        #Display menue here here
        self.student_name = StringVar()
 
        # Prompt, Entry and Button... will be more buttons added eventually
        self.prompt = Label(self, text = "Select one of the 3 menu options")
        self.prompt.grid(row = 0, column = 0)
         
        #Radio Button Menu options
        #Button to enter students name
        self.button_selected = IntVar()
        self.button_selected.set(1)       
        
        #self.button_selected.get() == 1
        self.menu_button = Radiobutton(self, text = "Add student name",
                    variable = self.button_selected, value = 1)        
        self.menu_button.grid(row = 3, column = 0) 
        
        self.prompt = Label(self, text = "Enter students name: ")
        self.prompt.grid(row = 7, column = 0)
        #text box
        self.input = Entry(self)
        self.input.grid(row = 7, column = 1)

       # submit button
        self.button_submit = Button(self, text = "Submit",
                                command = self.set_names)
        self.button_submit.grid(row = 7, column = 2)

        #print(list(student_scores.values()))

        #close test file
        student_scores.close()

    #function to set student names
    def set_names(self):
        student_name = [self.student_name.get()]
        print("submitt function pressed")
                   
asn_frame = MyFrame()
asn_frame.mainloop()
Yoriz write Dec-18-2022, 08:07 PM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply


Messages In This Thread
Trying to add data into a shelf from a submit button - by TWB - Dec-18-2022, 07:02 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,488 Feb-13-2022, 01:57 PM
Last Post: dford
  Button to add data to database and listbox SalsaBeanDip 1 2,916 Dec-06-2020, 10:13 PM
Last Post: Larz60+
  Database Submit Entry Syntax Error Melford 27 7,951 Jan-27-2020, 04:20 PM
Last Post: Denni
  Problem with Submit button Tkinter Reldaing 2 3,711 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,119 Jan-02-2020, 04:32 PM
Last Post: Denni
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 5,068 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