fixed CTkRadioButton bug with variable

This commit is contained in:
Tom Schimansky 2022-05-12 23:56:00 +02:00
parent b99f384241
commit a688d07b2a
4 changed files with 35 additions and 25 deletions

View File

@ -319,25 +319,25 @@ class CTkCheckBox(CTkBaseClass):
self.check_state = True
self.draw()
if self.function is not None:
self.function()
if self.variable is not None and not from_variable_callback:
self.variable_callback_blocked = True
self.variable.set(self.onvalue)
self.variable_callback_blocked = False
if self.function is not None:
self.function()
def deselect(self, from_variable_callback=False):
self.check_state = False
self.draw()
if self.function is not None:
self.function()
if self.variable is not None and not from_variable_callback:
self.variable_callback_blocked = True
self.variable.set(self.offvalue)
self.variable_callback_blocked = False
if self.function is not None:
self.function()
def get(self):
return self.onvalue if self.check_state is True else self.offvalue

View File

@ -76,9 +76,15 @@ class CTkFrame(CTkBaseClass):
self.apply_widget_scaling(self.border_width))
if no_color_updates is False or requires_recoloring:
self.canvas.itemconfig("inner_parts",
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
if self.fg_color is None:
self.canvas.itemconfig("inner_parts",
fill=CTkThemeManager.single_color(self.bg_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
else:
self.canvas.itemconfig("inner_parts",
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
self.canvas.itemconfig("border_parts",
fill=CTkThemeManager.single_color(self.border_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.border_color, self.appearance_mode))

View File

@ -74,22 +74,23 @@ class CTkLabel(CTkBaseClass):
self.apply_widget_scaling(self.corner_radius),
0)
self.canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
if no_color_updates is False or requires_recoloring:
if CTkThemeManager.single_color(self.fg_color, self.appearance_mode) is not None:
self.canvas.itemconfig("inner_parts",
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
if CTkThemeManager.single_color(self.fg_color, self.appearance_mode) is not None:
self.canvas.itemconfig("inner_parts",
fill=CTkThemeManager.single_color(self.fg_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
self.text_label.configure(fg=CTkThemeManager.single_color(self.text_color, self.appearance_mode),
bg=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
else:
self.canvas.itemconfig("inner_parts",
fill=CTkThemeManager.single_color(self.bg_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.text_label.configure(fg=CTkThemeManager.single_color(self.text_color, self.appearance_mode),
bg=CTkThemeManager.single_color(self.fg_color, self.appearance_mode))
else:
self.canvas.itemconfig("inner_parts",
fill=CTkThemeManager.single_color(self.bg_color, self.appearance_mode),
outline=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.text_label.configure(fg=CTkThemeManager.single_color(self.text_color, self.appearance_mode),
bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.text_label.configure(fg=CTkThemeManager.single_color(self.text_color, self.appearance_mode),
bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
self.canvas.configure(bg=CTkThemeManager.single_color(self.bg_color, self.appearance_mode))
def configure(self, *args, **kwargs):
require_redraw = False # some attribute changes require a call of self.draw() at the end

View File

@ -270,14 +270,17 @@ class CTkRadioButton(CTkBaseClass):
self.deselect(from_variable_callback=True)
def invoke(self, event=0):
if self.function is not None:
self.function()
if self.state == tkinter.NORMAL:
if self.check_state is False:
self.check_state = True
self.select()
if self.function is not None:
try:
self.function()
except:
pass
def select(self, from_variable_callback=False):
self.check_state = True
self.border_width = self.border_width_checked