Python Forum
[Tkinter] tkinter.TclError: expected integer but got " "
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] tkinter.TclError: expected integer but got " "
#1
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
# 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()
Reply


Messages In This Thread
tkinter.TclError: expected integer but got " " - by TWB - Feb-04-2023, 02:35 PM
RE: Error checking for Integer Field - by TWB - Feb-19-2023, 05:11 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  tkinter.TclError: can't invoke "canvas" command cybertooth 8 6,057 Feb-23-2023, 06:58 PM
Last Post: deanhystad
  [Tkinter] _tkinter.TclError: can't invoke "destroy" command: application has been destroyed knoxvilles_joker 6 15,676 Apr-25-2021, 08:41 PM
Last Post: knoxvilles_joker
  "tkinter.TclError: NULL main window" Rama02 1 5,882 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  [Tkinter] _tkinter.TclError: bitmap "Icon.gif" not defined djwilson0495 2 13,003 Aug-05-2020, 02:27 PM
Last Post: wuf
  [Tkinter] _tkinter.TclError: image "pyimage2" doesn't exist Killdoz 1 10,697 May-30-2020, 09:48 AM
Last Post: menator01
  Converting Entry field value to integer in tkinter scratchmyhead 2 4,985 May-11-2020, 03:41 PM
Last Post: scratchmyhead
  tkinter.TclError: bad window path name kenwatts275 3 14,860 Apr-26-2020, 08:16 PM
Last Post: kenwatts275

Forum Jump:

User Panel Messages

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