mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
readme update for CTk class and bug fix for .destroy() for all widgets
This commit is contained in:
parent
063c1f8b6a
commit
af73c9ad5f
55
Readme.md
55
Readme.md
@ -35,7 +35,7 @@ To test customtkinter you can try this simple example with only a single button:
|
||||
import tkinter
|
||||
import customtkinter # <- import the CustomTkinter module
|
||||
|
||||
root_tk = tkinter.Tk() # create the Tk window like you normally do
|
||||
root_tk = customtkinter.CTk() # create CTk window like you do with the Tk window (you can also use normal tkinter.Tk window)
|
||||
root_tk.geometry("400x240")
|
||||
root_tk.title("CustomTkinter Test")
|
||||
|
||||
@ -69,23 +69,25 @@ button = customtkinter.CTkButton(master=root_tk,
|
||||
button.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
|
||||
```
|
||||
|
||||
### How to use macOS dark mode?
|
||||
If you have a python version with Tcl/Tk >= 8.6.9, then you can enable the macOS
|
||||
darkmode. Currently only the anaconda python versions have Tcl/Tk >= 8.6.9.
|
||||
So if you want a dark window titlebar, you have to install anaconda python version
|
||||
### Dark mode and dark title-bar on macOS
|
||||
If you have a python version with Tcl/Tk >= 8.6.9, then you automatically get
|
||||
a dark title bar with macOS dark-mode on, if you use the `customtkinter.Ctk` class to create
|
||||
the window instead of the normal `tkinterTk` class. Currently, only the anaconda python versions have Tcl/Tk >= 8.6.9.
|
||||
So if you want a dark window title-bar, you have to install anaconda python version
|
||||
or miniconda.
|
||||
```python
|
||||
import tkinter
|
||||
import customtkinter
|
||||
|
||||
customtkinter.enable_macos_darkmode()
|
||||
customtkinter.set_appearance_mode("System")
|
||||
root_tk = customtkinter.CTk()
|
||||
|
||||
... the program ...
|
||||
|
||||
customtkinter.disable_macos_darkmode()
|
||||
root_tk.mainloop()
|
||||
|
||||
```
|
||||
which gives the following with the above simple button program:
|
||||
The above results in a window with a black title-bar with macOS dark-mode turned on:
|
||||
|
||||
![](documentation_images/simple_macOS_darkmode_test.png)
|
||||
|
||||
@ -96,14 +98,14 @@ the System mode:
|
||||
|
||||
### Advanced example with multiple CTkFrames
|
||||
|
||||
Here I used the ``customtkinter.enable_macos_darkmode()`` command to
|
||||
enable the macOS darkmode, and used multpiple CTkFrames. It has some
|
||||
Here I used the ``customtkinter.CTk()`` class to create the main window with two CTkFrame's and
|
||||
set the appearance mode to `System`. It has some
|
||||
kind of a menu on the left side, and I used all CustomTkinter elements
|
||||
there are at the moment.Maybe this is a good reference if you want to
|
||||
create your own application with this library.
|
||||
(Code: /complex_example.py)
|
||||
|
||||
With macOS darkmode turned on, it looks like this:
|
||||
With macOS dark-mode turned on, it looks like this:
|
||||
|
||||
![](documentation_images/complex_example_dark.png)
|
||||
|
||||
@ -147,6 +149,37 @@ created two buttons with a bell and a settings image on them:
|
||||
|
||||
## Documentation - CustomTkinter Elements
|
||||
|
||||
### CTk
|
||||
You can use the normal ``kinter.Tk`` class to create the root window,
|
||||
but if you want a background color that changes with the appearance mode and a dark title-bar on macOS,
|
||||
you should use the `customtkinter.CTk` class which behaves exactly like the normal Tk
|
||||
class, except that you can also set a tuple color as bg color.
|
||||
|
||||
Example Code:
|
||||
|
||||
```python
|
||||
root_tk = customtkinter.CTk()
|
||||
|
||||
... program ...
|
||||
|
||||
root_tk.mainloop()
|
||||
```
|
||||
<details>
|
||||
<summary>Show all arguments:</summary>
|
||||
|
||||
argument | value
|
||||
--- | ---
|
||||
bg_color or bg | tuple: (light_color, dark_color) or single color
|
||||
|
||||
CTk Methods:
|
||||
|
||||
```python
|
||||
root_tk = customtkinter.CTk()
|
||||
# configure bg color with single or tuple color
|
||||
root_tk.configure(bg_color="gray20")
|
||||
root_tk.configure(bg_color=(<light-mode color>, <dark-mode color>))
|
||||
```
|
||||
|
||||
### CTkButton
|
||||
Examle Code:
|
||||
```python
|
||||
|
@ -1,4 +1,4 @@
|
||||
__version__ = "1.5"
|
||||
__version__ = "1.6"
|
||||
|
||||
from .customtkinter_button import CTkButton
|
||||
from .customtkinter_slider import CTkSlider
|
||||
|
@ -119,6 +119,10 @@ class AppearanceModeTracker():
|
||||
def add(cls, callback):
|
||||
cls.callback_list.append(callback)
|
||||
|
||||
@classmethod
|
||||
def remove(cls, callback):
|
||||
cls.callback_list.remove(callback)
|
||||
|
||||
@classmethod
|
||||
def get_mode(cls):
|
||||
return cls.appearance_mode
|
||||
@ -141,10 +145,19 @@ class AppearanceModeTracker():
|
||||
|
||||
if cls.appearance_mode == 0:
|
||||
for callback in cls.callback_list:
|
||||
try:
|
||||
callback("Light")
|
||||
except Exception:
|
||||
print("error callback")
|
||||
continue
|
||||
|
||||
elif cls.appearance_mode == 1:
|
||||
for callback in cls.callback_list:
|
||||
try:
|
||||
callback("Dark")
|
||||
except Exception:
|
||||
print("error callback")
|
||||
continue
|
||||
|
||||
|
||||
AppearanceModeTracker.init_listener_function()
|
||||
|
@ -101,6 +101,10 @@ class CTkButton(tkinter.Frame):
|
||||
self.bind('<Configure>', self.update_dimensions)
|
||||
self.draw()
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.set_appearance_mode)
|
||||
super().destroy()
|
||||
|
||||
def configure_basic_grid(self):
|
||||
# Configuration of a basic grid (2x2) in which all elements of CTkButtons are centered on one row and one column
|
||||
self.grid_rowconfigure(0, weight=1)
|
||||
|
@ -91,6 +91,10 @@ class CTkCheckBox(tkinter.Frame):
|
||||
|
||||
self.draw()
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.set_appearance_mode)
|
||||
super().destroy()
|
||||
|
||||
def detect_color_of_master(self):
|
||||
if isinstance(self.master, CTkFrame):
|
||||
return self.master.fg_color
|
||||
|
@ -54,6 +54,10 @@ class CTkEntry(tkinter.Frame):
|
||||
|
||||
self.draw()
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.change_appearance_mode)
|
||||
super().destroy()
|
||||
|
||||
def detect_color_of_master(self):
|
||||
if isinstance(self.master, CTkFrame):
|
||||
return self.master.fg_color
|
||||
|
@ -58,6 +58,10 @@ class CTkFrame(tkinter.Frame):
|
||||
|
||||
self.draw()
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.change_appearance_mode)
|
||||
super().destroy()
|
||||
|
||||
def detect_color_of_master(self):
|
||||
if isinstance(self.master, CTkFrame):
|
||||
return self.master.fg_color
|
||||
|
@ -69,6 +69,10 @@ class CTkLabel(tkinter.Frame):
|
||||
|
||||
self.draw()
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.change_appearance_mode)
|
||||
super().destroy()
|
||||
|
||||
def detect_color_of_master(self):
|
||||
if isinstance(self.master, CTkFrame):
|
||||
return self.master.fg_color
|
||||
|
@ -46,6 +46,10 @@ class CTkProgressBar(tkinter.Frame):
|
||||
# set progress
|
||||
self.set(self.value)
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.change_appearance_mode)
|
||||
super().destroy()
|
||||
|
||||
def detect_color_of_master(self):
|
||||
if isinstance(self.master, CTkFrame):
|
||||
return self.master.fg_color
|
||||
|
@ -64,6 +64,10 @@ class CTkSlider(tkinter.Frame):
|
||||
|
||||
self.draw()
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.change_appearance_mode)
|
||||
super().destroy()
|
||||
|
||||
def detect_color_of_master(self):
|
||||
if isinstance(self.master, CTkFrame):
|
||||
return self.master.fg_color
|
||||
|
@ -30,6 +30,7 @@ class CTk(tkinter.Tk):
|
||||
super().configure(bg=CTkColorManager.single_color(self.bg_color, self.appearance_mode))
|
||||
|
||||
def destroy(self):
|
||||
AppearanceModeTracker.remove(self.set_appearance_mode)
|
||||
self.disable_macos_dark_title_bar()
|
||||
super().destroy()
|
||||
|
||||
@ -65,6 +66,4 @@ class CTk(tkinter.Tk):
|
||||
elif mode_string.lower() == "light":
|
||||
self.appearance_mode = 0
|
||||
|
||||
print("set",self.bg_color)
|
||||
|
||||
super().configure(bg=CTkColorManager.single_color(self.bg_color, self.appearance_mode))
|
||||
|
Loading…
Reference in New Issue
Block a user