Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed locale-dependent canvas scaling bug #2468

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions customtkinter/windows/widgets/scaling/scaling_base_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,24 @@ def _get_widget_scaling(self) -> float:
def _get_window_scaling(self) -> float:
return self.__window_scaling

def _apply_widget_scaling(self, value: Union[int, float]) -> Union[float]:
# Some parts of Tk - notably canvas - are very buggy with floats, because they use locale-dependent parsing
# (and thus might not recognize "." as the decimal point)
# https://wiki.tcl-lang.org/page/locale
# https://github.com/python/cpython/issues/56767
# Hence, we must ensure any integer value stays that way
def _apply_widget_scaling(self, value: Union[int, float]) -> Union[int, float]:
assert self.__scaling_type == "widget"
return value * self.__widget_scaling
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]:
def _reverse_widget_scaling(self, value: Union[int, float]) -> Union[int, float]:
assert self.__scaling_type == "widget"
return value / self.__widget_scaling
if isinstance(value, float):
return value / self.__widget_scaling
else:
return int(value / self.__widget_scaling)

def _apply_window_scaling(self, value: Union[int, float]) -> int:
assert self.__scaling_type == "window"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import locale
import tkinter
import customtkinter # <- import the CustomTkinter module

locale.setlocale(locale.LC_NUMERIC, 'de_DE') # to verify that the canvas float argument bug is properly averted
customtkinter.ScalingTracker.set_window_scaling(0.5)

customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import locale
import tkinter
import customtkinter # <- import the CustomTkinter module

locale.setlocale(locale.LC_NUMERIC, 'de_DE') # to verify that the canvas float argument bug is properly averted
customtkinter.ScalingTracker.set_window_scaling(0.5)

customtkinter.set_appearance_mode("dark") # Modes: "System" (standard), "Dark", "Light"
Expand Down