CustomTkinter: tkinter.TclError: bad screen distance "200.0"

Python 3.10 Windows 11

When i init a CtkFrame like this:

 def __init__(self, parent, data):
        super().__init__(parent)

i always get

_tkinter.TclError: bad screen distance "200.0"

The error is located at ctk_frame.py line 41:

self.canvas = CTkCanvas(master=self, highlightthickness=0, width=self.apply_widget_scaling(self._current_width), height=self.apply_widget_scaling(self._current_height))

when changing to:


        self.canvas = CTkCanvas(master=self,
                                highlightthickness=0,
                                width=int(self.apply_widget_scaling(self._current_width)),
                                height=int(self.apply_widget_scaling(self._current_height)))

it works, but then next “TclError: bad screen distance” is located in ctk_label.py, line 47.

Tried it on several computers, but error is always the same.

Any idea what this might cause? looks it somehow receives a float instead of an int, but width and height are default values.

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 16 (1 by maintainers)

Most upvoted comments

I found that you need the float value, otherwise scrollbars arn’t working. I changed the code above to:

    def _apply_widget_scaling(self, value: Union[int, float]) -> Union[float, int]:
        assert self.__scaling_type == "widget"
        if isinstance(value, float):
            return value * self.__widget_scaling
        else:
            return int(value * self.__widget_scaling)

    def _reverse_widget_scaling(self, value: Union[int, float]) -> Union[float, int]:
        assert self.__scaling_type == "widget"
        if isinstance(value, float):
            return value / self.__widget_scaling
        else:
            return int(value / self.__widget_scaling)

I will have a look.