fixed scaling issues

This commit is contained in:
Tom Schimansky
2022-04-21 20:30:46 +02:00
parent 6342bf8034
commit 245a8d81bc
6 changed files with 43 additions and 7 deletions

View File

@ -72,6 +72,12 @@ class CTkCheckBox(CTkBaseClass):
self.grid_columnconfigure(2, weight=1)
self.grid_rowconfigure(0, weight=1)
self.bg_canvas = CTkCanvas(master=self,
highlightthickness=0,
width=self.width * self.scaling,
height=self.height * self.scaling)
self.bg_canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=3, rowspan=1, sticky="nswe")
self.canvas = CTkCanvas(master=self,
highlightthickness=0,
width=self.width * self.scaling,
@ -116,7 +122,7 @@ class CTkCheckBox(CTkBaseClass):
else:
self.canvas.delete("checkmark")
self.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.bg_canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
if self.check_state is True:

View File

@ -68,6 +68,12 @@ class CTkRadioButton(CTkBaseClass):
self.grid_columnconfigure(1, weight=0, minsize=6 * self.scaling)
self.grid_columnconfigure(2, weight=1)
self.bg_canvas = CTkCanvas(master=self,
highlightthickness=0,
width=self.width * self.scaling,
height=self.height * self.scaling)
self.bg_canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=3, rowspan=1, sticky="nswe")
self.canvas = CTkCanvas(master=self,
highlightthickness=0,
width=self.width * self.scaling,
@ -102,8 +108,8 @@ class CTkRadioButton(CTkBaseClass):
self.corner_radius * self.scaling,
self.border_width * self.scaling)
self.bg_canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
if self.check_state is False:
self.canvas.itemconfig("border_parts",

View File

@ -73,6 +73,12 @@ class CTkSwitch(CTkBaseClass):
self.grid_columnconfigure(1, weight=0, minsize=6 * self.scaling)
self.grid_columnconfigure(2, weight=0)
self.bg_canvas = CTkCanvas(master=self,
highlightthickness=0,
width=self.width * self.scaling,
height=self.height * self.scaling)
self.bg_canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=3, rowspan=1, sticky="nswe")
self.canvas = CTkCanvas(master=self,
highlightthickness=0,
width=self.width * self.scaling,
@ -127,7 +133,7 @@ class CTkSwitch(CTkBaseClass):
0, "w")
if no_color_updates is False or requires_recoloring:
self.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.bg_canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
if self.border_color is None:

View File

@ -2,6 +2,7 @@ import tkinter
import tkinter.ttk as ttk
import copy
import re
import math
from .ctk_tk import CTk
from .ctk_toplevel import CTkToplevel
@ -76,9 +77,9 @@ class CTkBaseClass(tkinter.Frame):
def update_dimensions_event(self, event):
# only redraw if dimensions changed (for performance)
if self.width != int(event.width * self.scaling) or self.height != int(event.height * self.scaling):
self.width = int(event.width / self.scaling) # adjust current size according to new size given by event
self.height = int(event.height / self.scaling) # width and height are independent of the scale
if self.width != math.floor(event.width * self.scaling) or self.height != math.floor(event.height * self.scaling):
self.width = event.width / self.scaling # adjust current size according to new size given by event
self.height = event.height / self.scaling # width and height are independent of the scale
self.draw(no_color_updates=True) # faster drawing without color changes