mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
refined CTkRadioButton and complex_example.py, version 3.3
This commit is contained in:
parent
6c976245aa
commit
0d32213325
3
MANIFEST.in
Normal file
3
MANIFEST.in
Normal file
@ -0,0 +1,3 @@
|
||||
include customtkinter/assets/*
|
||||
include customtkinter/assets/Roboto/*
|
||||
include customtkinter/assets/themes/*
|
@ -1,4 +1,4 @@
|
||||
__version__ = "3.0"
|
||||
__version__ = "3.3"
|
||||
|
||||
from .customtkinter_dialog import CTkDialog
|
||||
from .customtkinter_button import CTkButton
|
||||
|
@ -94,11 +94,16 @@ class CTkCheckBox(tkinter.Frame):
|
||||
self.textvariable = textvariable
|
||||
self.variable_callback_name = None
|
||||
|
||||
# configure grid system
|
||||
self.grid_columnconfigure(0, weight=0)
|
||||
self.grid_columnconfigure(1, weight=0, minsize=6)
|
||||
self.grid_columnconfigure(2, weight=1)
|
||||
|
||||
self.canvas = CTkCanvas(master=self,
|
||||
highlightthickness=0,
|
||||
width=self.width,
|
||||
height=self.height)
|
||||
self.canvas.pack(side='left')
|
||||
self.canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=1)
|
||||
|
||||
self.draw_engine = CTkDrawEngine(self.canvas, CTkSettings.preferred_drawing_method)
|
||||
|
||||
@ -160,11 +165,11 @@ class CTkCheckBox(tkinter.Frame):
|
||||
|
||||
if self.text_label is None:
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
width=len(self.text_color),
|
||||
font=self.text_font)
|
||||
self.text_label.pack(side='right', padx=6)
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.configure(fg=CTkThemeManager.single_color(self.text_color, self.appearance_mode))
|
||||
@ -262,9 +267,9 @@ class CTkCheckBox(tkinter.Frame):
|
||||
def set_text(self, text):
|
||||
self.text = text
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(text=self.text, width=len(self.text))
|
||||
self.text_label.configure(text=self.text)
|
||||
else:
|
||||
sys.stderr.write("ERROR (CTkButton): Cant change text because button has no text.")
|
||||
sys.stderr.write("ERROR (CTkButton): Cant change text because checkbox has no text.")
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.hover is True:
|
||||
|
@ -41,17 +41,17 @@ class CTkDialog:
|
||||
self.top.grab_set()
|
||||
|
||||
self.label_frame = CTkFrame(master=self.top,
|
||||
corner_radius=0,
|
||||
fg_color=CTkThemeManager.single_color(self.window_bg_color, self.appearance_mode),
|
||||
width=300,
|
||||
height=self.height-100)
|
||||
corner_radius=0,
|
||||
fg_color=self.window_bg_color,
|
||||
width=300,
|
||||
height=self.height-100)
|
||||
self.label_frame.place(relx=0.5, rely=0, anchor=tkinter.N)
|
||||
|
||||
self.button_and_entry_frame = CTkFrame(master=self.top,
|
||||
corner_radius=0,
|
||||
fg_color=CTkThemeManager.single_color(self.window_bg_color, self.appearance_mode),
|
||||
width=300,
|
||||
height=100)
|
||||
corner_radius=0,
|
||||
fg_color=self.window_bg_color,
|
||||
width=300,
|
||||
height=100)
|
||||
self.button_and_entry_frame.place(relx=0.5, rely=1, anchor=tkinter.S)
|
||||
|
||||
self.myLabel = CTkLabel(master=self.label_frame,
|
||||
|
@ -93,11 +93,16 @@ class CTkRadioButton(tkinter.Frame):
|
||||
self.textvariable = textvariable
|
||||
self.variable_callback_name = None
|
||||
|
||||
# configure grid system
|
||||
self.grid_columnconfigure(0, weight=0)
|
||||
self.grid_columnconfigure(1, weight=0, minsize=6)
|
||||
self.grid_columnconfigure(2, weight=1)
|
||||
|
||||
self.canvas = CTkCanvas(master=self,
|
||||
highlightthickness=0,
|
||||
width=self.width,
|
||||
height=self.height)
|
||||
self.canvas.pack(side='left')
|
||||
self.canvas.grid(row=0, column=0, padx=0, pady=0, columnspan=1)
|
||||
|
||||
self.draw_engine = CTkDrawEngine(self.canvas, CTkSettings.preferred_drawing_method)
|
||||
|
||||
@ -159,11 +164,11 @@ class CTkRadioButton(tkinter.Frame):
|
||||
|
||||
if self.text_label is None:
|
||||
self.text_label = tkinter.Label(master=self,
|
||||
bd=0,
|
||||
text=self.text,
|
||||
justify=tkinter.LEFT,
|
||||
width=len(self.text_color),
|
||||
font=self.text_font)
|
||||
self.text_label.pack(side='right', padx=6)
|
||||
self.text_label.grid(row=0, column=2, padx=0, pady=0, sticky="w")
|
||||
self.text_label["anchor"] = "w"
|
||||
|
||||
self.text_label.configure(fg=CTkThemeManager.single_color(self.text_color, self.appearance_mode))
|
||||
@ -266,9 +271,9 @@ class CTkRadioButton(tkinter.Frame):
|
||||
def set_text(self, text):
|
||||
self.text = text
|
||||
if self.text_label is not None:
|
||||
self.text_label.configure(text=self.text, width=len(self.text))
|
||||
self.text_label.configure(text=self.text)
|
||||
else:
|
||||
sys.stderr.write("ERROR (CTkButton): Cant change text because button has no text.")
|
||||
sys.stderr.write("ERROR (CTkButton): Cant change text because radiobutton has no text.")
|
||||
|
||||
def on_enter(self, event=0):
|
||||
if self.hover is True:
|
||||
|
@ -9,7 +9,7 @@ customtkinter.set_default_color_theme("blue") # Themes: "blue" (standard), "gre
|
||||
|
||||
class App(customtkinter.CTk):
|
||||
|
||||
WIDTH = 700
|
||||
WIDTH = 750
|
||||
HEIGHT = 500
|
||||
|
||||
def __init__(self):
|
||||
@ -82,9 +82,10 @@ class App(customtkinter.CTk):
|
||||
self.frame_right.rowconfigure(i, weight=1)
|
||||
self.frame_right.rowconfigure(6, weight=10)
|
||||
self.frame_right.columnconfigure(0, weight=1)
|
||||
self.frame_right.columnconfigure(1, weight=0)
|
||||
|
||||
self.frame_info = customtkinter.CTkFrame(master=self.frame_right)
|
||||
self.frame_info.grid(row=0, column=0, columnspan=2, rowspan=4, pady=20, padx=20, sticky="wens")
|
||||
self.frame_info.grid(row=0, column=0, columnspan=1, rowspan=4, pady=20, padx=20, sticky="nsew")
|
||||
|
||||
# ============ frame_right -> frame_info ============
|
||||
|
||||
@ -96,37 +97,35 @@ class App(customtkinter.CTk):
|
||||
"amet consetetur sadipscing elitr,\n" +
|
||||
"sed diam nonumy eirmod tempor\n" +
|
||||
"invidunt ut labore",
|
||||
width=240,
|
||||
height=100,
|
||||
fg_color=("white", "gray38"), # <- custom tuple-color
|
||||
justify=tkinter.LEFT)
|
||||
self.label_info_1.grid(column=0, row=0, sticky="nwe", padx=15, pady=15)
|
||||
|
||||
self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info, width=240)
|
||||
self.progressbar = customtkinter.CTkProgressBar(master=self.frame_info)
|
||||
self.progressbar.grid(row=1, column=0, sticky="ew", padx=15, pady=15)
|
||||
|
||||
# ============ frame_right <- ============
|
||||
self.radio_var = tkinter.IntVar(value=0)
|
||||
|
||||
self.label_radio_group = customtkinter.CTkLabel(master=self.frame_right,
|
||||
fg_color=("white", "gray30"), # <- custom tuple-color
|
||||
text="CTkRadioButton Group:")
|
||||
self.label_radio_group.grid(row=0, column=2, columnspan=1, pady=0, padx=20, sticky="wes")
|
||||
self.label_radio_group.grid(row=0, column=1, columnspan=1, pady=20, padx=10, sticky="")
|
||||
|
||||
self.radio_button_1 = customtkinter.CTkRadioButton(master=self.frame_right,
|
||||
variable=self.radio_var,
|
||||
value=0)
|
||||
self.radio_button_1.grid(row=1, column=2, pady=10, padx=20, sticky="")
|
||||
variable=self.radio_var,
|
||||
value=0)
|
||||
self.radio_button_1.grid(row=1, column=1, pady=10, padx=20, sticky="n")
|
||||
|
||||
self.radio_button_2 = customtkinter.CTkRadioButton(master=self.frame_right,
|
||||
variable=self.radio_var,
|
||||
value=1)
|
||||
self.radio_button_2.grid(row=2, column=2, pady=10, padx=20, sticky="")
|
||||
self.radio_button_2.grid(row=2, column=1, pady=10, padx=20, sticky="n")
|
||||
|
||||
self.radio_button_3 = customtkinter.CTkRadioButton(master=self.frame_right,
|
||||
variable=self.radio_var,
|
||||
value=2)
|
||||
self.radio_button_3.grid(row=3, column=2, pady=10, padx=20, sticky="")
|
||||
self.radio_button_3.grid(row=3, column=1, pady=10, padx=20, sticky="n")
|
||||
|
||||
#self.radio_button_1.select()
|
||||
#self.radio_button_1.deselect()
|
||||
@ -136,35 +135,35 @@ class App(customtkinter.CTk):
|
||||
to=0,
|
||||
number_of_steps=3,
|
||||
command=self.progressbar.set)
|
||||
self.slider_1.grid(row=4, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
||||
self.slider_1.grid(row=4, column=0, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
self.slider_1.set(0.7)
|
||||
|
||||
self.slider_2 = customtkinter.CTkSlider(master=self.frame_right,
|
||||
command=self.progressbar.set)
|
||||
self.slider_2.grid(row=5, column=0, columnspan=2, pady=10, padx=20, sticky="we")
|
||||
self.slider_2.grid(row=5, column=0, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
self.slider_2.set(0.7)
|
||||
|
||||
self.slider_button_1 = customtkinter.CTkButton(master=self.frame_right,
|
||||
height=25,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.slider_button_1.grid(row=4, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
height=25,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.slider_button_1.grid(row=4, column=1, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
|
||||
self.slider_button_2 = customtkinter.CTkButton(master=self.frame_right,
|
||||
height=25,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.slider_button_2.grid(row=5, column=2, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
height=25,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.slider_button_2.grid(row=5, column=1, columnspan=1, pady=10, padx=20, sticky="we")
|
||||
|
||||
self.entry = customtkinter.CTkEntry(master=self.frame_right,
|
||||
width=120,
|
||||
placeholder_text="CTkEntry")
|
||||
self.entry.grid(row=7, column=0, columnspan=2, pady=20, padx=20, sticky="we")
|
||||
self.entry.grid(row=7, column=0, columnspan=1, pady=20, padx=20, sticky="we")
|
||||
|
||||
self.button_5 = customtkinter.CTkButton(master=self.frame_right,
|
||||
text="CTkButton",
|
||||
command=self.button_event)
|
||||
self.button_5.grid(row=7, column=2, columnspan=1, pady=20, padx=20, sticky="we")
|
||||
self.button_5.grid(row=7, column=1, columnspan=1, pady=20, padx=20, sticky="we")
|
||||
|
||||
self.progressbar.set(0.5)
|
||||
|
||||
|
@ -46,4 +46,12 @@ entry_1.pack(pady=y_padding, padx=10)
|
||||
checkbox_1 = customtkinter.CTkCheckBox(master=frame_1, command=check_box_function)
|
||||
checkbox_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
radiobutton_var = tkinter.IntVar()
|
||||
|
||||
radiobutton_1 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=1)
|
||||
radiobutton_1.pack(pady=y_padding, padx=10)
|
||||
|
||||
radiobutton_2 = customtkinter.CTkRadioButton(master=frame_1, variable=radiobutton_var, value=2)
|
||||
radiobutton_2.pack(pady=y_padding, padx=10)
|
||||
|
||||
root_tk.mainloop()
|
||||
|
6
setup.py
6
setup.py
@ -19,15 +19,17 @@ def read(filename):
|
||||
|
||||
|
||||
setup(name="customtkinter",
|
||||
version="3.0",
|
||||
version="3.3",
|
||||
author="Tom Schimansky",
|
||||
license="Creative Commons Zero v1.0 Universal",
|
||||
url="https://github.com/TomSchimansky/CustomTkinter",
|
||||
description="Create modern looking gui with tkinter and python",
|
||||
long_description_content_type="text/markdown",
|
||||
long_description=read('Readme_pypi.md'),
|
||||
include_package_data=True,
|
||||
packages=["customtkinter"],
|
||||
classifiers=["Operating System :: OS Independent",
|
||||
"Programming Language :: Python :: 3",
|
||||
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication"],
|
||||
install_requires=["darkdetect"])
|
||||
install_requires=["darkdetect",
|
||||
"pyglet"])
|
||||
|
@ -65,8 +65,7 @@ class TestApp(customtkinter.CTk):
|
||||
self.frame_2 = customtkinter.CTkFrame(master=self.ctk_frame, width=200, height=60)
|
||||
self.frame_2.place(relx=0.5, y=y + 80, anchor=tkinter.CENTER)
|
||||
|
||||
self.button_2 = customtkinter.CTkButton(master=self.ctk_frame, border_width=3, border_color=customtkinter.CTkThemeManager.MAIN_HOVER_COLOR,
|
||||
)
|
||||
self.button_2 = customtkinter.CTkButton(master=self.ctk_frame, border_width=3)
|
||||
self.button_2.place(relx=0.5, y=y + 160, anchor=tkinter.CENTER)
|
||||
|
||||
self.entry_2 = customtkinter.CTkEntry(master=self.ctk_frame)
|
||||
|
@ -1,44 +1,23 @@
|
||||
import tkinter
|
||||
import customtkinter
|
||||
import time
|
||||
|
||||
customtkinter.set_appearance_mode("light")
|
||||
|
||||
|
||||
class ExampleApp(customtkinter.CTk):
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
self.geometry("400x400")
|
||||
self.title("main CTk window")
|
||||
time.sleep(0.5)
|
||||
self.resizable(False, False)
|
||||
|
||||
self.b1 = customtkinter.CTkButton(self, text="Add another window", command=self.newWindow)
|
||||
self.b1.pack(side="top", padx=40, pady=40)
|
||||
self.c1 = customtkinter.CTkCheckBox(self, text="dark mode", command=self.change_mode)
|
||||
self.c1.pack()
|
||||
self.count = 0
|
||||
self.geometry("500x400")
|
||||
|
||||
def change_mode(self):
|
||||
if self.c1.get() == 1:
|
||||
customtkinter.set_appearance_mode("dark")
|
||||
else:
|
||||
customtkinter.set_appearance_mode("light")
|
||||
|
||||
def newWindow(self):
|
||||
self.count += 1
|
||||
self.button_1 = customtkinter.CTkButton(self, text="Create CTkToplevel", command=self.create_toplevel)
|
||||
self.button_1.pack(side="top", padx=40, pady=40)
|
||||
|
||||
def create_toplevel(self):
|
||||
window = customtkinter.CTkToplevel(self)
|
||||
window.configure(bg=("lime", "darkgreen"))
|
||||
window.title("CTkToplevel window")
|
||||
window.geometry("400x200")
|
||||
window.resizable(False, False)
|
||||
|
||||
label = customtkinter.CTkLabel(window, text=f"This is CTkToplevel window number {self.count}")
|
||||
label = customtkinter.CTkLabel(window, text="CTkToplevel window")
|
||||
label.pack(side="top", fill="both", expand=True, padx=40, pady=40)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
root = ExampleApp()
|
||||
time.sleep(0.5)
|
||||
root.mainloop()
|
||||
app = ExampleApp()
|
||||
app.mainloop()
|
Loading…
Reference in New Issue
Block a user