Feb-04-2023, 02:35 PM
(This post was last modified: Feb-04-2023, 07:46 PM by Yoriz.
Edit Reason: Title
)
Hello all,
I am trying to build a function that i can use to check a imput field that requires a integer to make sure a character hasn't been entered.
Anything I try gives me a error "tkinter.TclError: expected integer but got " "
It seems to catch the error before i can run any error checking
I have attached a snippet of the code below that is executable
Any help is always appreciated
I am trying to build a function that i can use to check a imput field that requires a integer to make sure a character hasn't been entered.
Anything I try gives me a error "tkinter.TclError: expected integer but got " "
It seems to catch the error before i can run any error checking
I have attached a snippet of the code below that is executable
Any help is always appreciated
# Introduction to Python Programming from tkinter import * import shelve import tkinter as tk from tkinter import ttk class MyFrame (Frame): def __init__(self): Frame.__init__(self) self.master.geometry("600x600") self.master.title("Student Scores") self.grid() #Display menue here here self.student_score = IntVar() self.student_score.set("") #label to prompt for input of score self.prompt = Label(self, text = "Enter students score: ") self.prompt.grid(row = 3, column = 0, sticky="W") #enable text field for score input self.input = Entry(self,textvariable=self.student_score) self.input.grid(row = 3, column = 2) #submit button self.button_submit = Button(self, text = "Submit", command = self.enter_student_scores) self.button_submit.grid(row = 10, column = 0, pady=20) #function to see entered student names and scores def enter_student_scores(self): student_score = self.student_score.get() #print output print(" Student Score is ",student_score) # function for error checking def error_checking(self): score = self.student_score.get() try: x = int(score) print("int is entered") except ValueError: print("Not a proper integer! Try it again") asn_frame = MyFrame() asn_frame.mainloop()