mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
fixed bug when resizing CTkButton and CTkEntry in grid, added auto resizing to CTkSlider and CTkProgressBar, changed Readme
This commit is contained in:
@@ -111,7 +111,7 @@ class CTkButton(tkinter.Frame):
|
||||
highlightthicknes=0,
|
||||
width=self.width,
|
||||
height=self.height)
|
||||
self.canvas.grid(row=0, column=0, rowspan=2, columnspan=2)
|
||||
self.canvas.grid(row=1, column=0, rowspan=2, columnspan=2)
|
||||
|
||||
# event bindings
|
||||
if self.hover is True:
|
||||
@@ -143,7 +143,7 @@ class CTkButton(tkinter.Frame):
|
||||
self.width = event.width
|
||||
self.height = event.height
|
||||
|
||||
self.canvas.config(width=self.width, height=self.height)
|
||||
# self.canvas.config(width=self.width, height=self.height)
|
||||
self.draw(no_color_updates=True) # fast drawing without color changes
|
||||
|
||||
def detect_color_of_master(self):
|
||||
|
||||
@@ -114,10 +114,10 @@ class CTkEntry(tkinter.Frame):
|
||||
def update_dimensions(self, event):
|
||||
# only redraw if dimensions changed (for performance)
|
||||
if self.width != event.width or self.height != event.height:
|
||||
# print(event.x, event.width, self.width)
|
||||
self.width = event.width
|
||||
self.height = event.height
|
||||
|
||||
self.canvas.config(width=self.width, height=self.height)
|
||||
self.draw()
|
||||
|
||||
def draw(self):
|
||||
|
||||
@@ -68,6 +68,9 @@ class CTkProgressBar(tkinter.Frame):
|
||||
height=self.height)
|
||||
self.canvas.place(x=0, y=0)
|
||||
|
||||
# Each time an item is resized due to pack position mode, the binding Configure is called on the widget
|
||||
self.bind('<Configure>', self.update_dimensions)
|
||||
|
||||
self.draw() # initial draw
|
||||
|
||||
if self.variable is not None:
|
||||
@@ -103,6 +106,14 @@ class CTkProgressBar(tkinter.Frame):
|
||||
else:
|
||||
return user_height
|
||||
|
||||
def update_dimensions(self, event):
|
||||
# only redraw if dimensions changed (for performance)
|
||||
if self.width != event.width or self.height != event.height:
|
||||
self.width = event.width
|
||||
self.height = event.height
|
||||
|
||||
self.draw()
|
||||
|
||||
def draw(self, no_color_updates=False):
|
||||
|
||||
# decide the drawing method
|
||||
|
||||
@@ -89,6 +89,9 @@ class CTkSlider(tkinter.Frame):
|
||||
self.canvas.bind("<Button-1>", self.clicked)
|
||||
self.canvas.bind("<B1-Motion>", self.clicked)
|
||||
|
||||
# Each time an item is resized due to pack position mode, the binding Configure is called on the widget
|
||||
self.bind('<Configure>', self.update_dimensions)
|
||||
|
||||
self.draw() # initial draw
|
||||
|
||||
if self.variable is not None:
|
||||
@@ -126,6 +129,14 @@ class CTkSlider(tkinter.Frame):
|
||||
else:
|
||||
return user_height
|
||||
|
||||
def update_dimensions(self, event):
|
||||
# only redraw if dimensions changed (for performance)
|
||||
if self.width != event.width or self.height != event.height:
|
||||
self.width = event.width
|
||||
self.height = event.height
|
||||
|
||||
self.draw()
|
||||
|
||||
def draw(self, no_color_updates=False):
|
||||
|
||||
# decide the drawing method
|
||||
|
||||
Reference in New Issue
Block a user