CTkEntry raises a TclError when using IntVar or DoubleVar

Author: legopitstopCreated Dec 2, 2022Updated Jun 24, 2026
Labelsbug

CTkEntry raises an error when you use IntVar or DoubleVar as a textvariable

customtkinter: 5.0.0 OS: Windows 10

Steps To Reproduce

  1. Run the below code in a python file.
  2. Enter any character that is not a number ex: "Hello, World"
  3. A TclError gets thrown every time you add or remove a character.

Observed Results

  • Only effects the IntVar and DoubleVar.
  • Throws the error when you remove or add characters.
  • Entering a valid value (integer for IntVar and float for DoubleVar) does not throw an error.
  • If you remove 0 from the entry box it will raise the error

Code:

python
from customtkinter import CTk, CTkEntry
import tkinter

root = CTk()
root.minsize(200,200)

var1 = tkinter.IntVar()
var2 = tkinter.IntVar()

entry1 = CTkEntry(root, textvariable=var1) # Raises an error
entry1.pack()

entry2 = tkinter.Entry(root, textvariable=var2) # Does not raise an error
entry2.pack()

root.mainloop()

Error:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Users\1589l\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 570, in get
    return self._tk.getint(value)
_tkinter.TclError: expected integer but got "hello, worl"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\1589l\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 1921, in __call__
    return self.func(*args)
  File "C:\Users\1589l\AppData\Local\Programs\Python\Python310\lib\site-packages\customtkinter\windows\widgets\ctk_entry.py", line 116, in _textvariable_callback
    if self._textvariable.get() == "":
  File "C:\Users\1589l\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 572, in get
    return int(self._tk.getdouble(value))
_tkinter.TclError: expected floating-point number but got "hello, worl"

Source: TomSchimansky/CustomTkinter