howto fall back to regular tkinter when non supported OS encountered? #541
-
Hi, I'm writing a cross platform app that runs on Windows, Mac and Linux. In Linux, CustomTkinter ends up looking really bad, as expected. What would be an elegant way to handle "fall back" to regular tkinter or similar, when a non-supported OS is encountered? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments 16 replies
-
@Free-Radical In that case you have to make two separate programs (one in tkinter and another in customtkinter). import sys
if sys.platform.startswith("linux"):
Normal_Tkinter() ##Link this to your normal tkinter app class/function. You can also combine both programs in one file. |
Beta Was this translation helpful? Give feedback.
-
Could you tell me why this is expected? I was thinking about making a Linux version as well but this might stop me from doing that. |
Beta Was this translation helpful? Give feedback.
-
What is your problem on Linux? Linux is supported by CustomTkinter. I can not test it on other distributions than Ubuntu and Kali Linux, but for me it always worked. |
Beta Was this translation helpful? Give feedback.
-
Good to hear, hopefully i'm doing something wrong (which is very possible , since I'm a noob at this), here's how a window looks using your code in Linux Mint 21 Cinnamon (looks fine in Windows/Mac) |
Beta Was this translation helpful? Give feedback.
-
Here is an Exampleimport tkinter
import customtkinter
import sys
import tkinter.ttk as ttk
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("Light")
def CTK_App():
app = customtkinter.CTk()
app.geometry("400x540")
app.title("CustomTkinter simple_example.py")
def button_function():
print("Button click", label_1.text_label.cget("text"))
def slider_function(value):
progressbar_1.set(value)
def check_box_function():
print("checkbox_1:", checkbox_1.get())
y_padding = 13
frame_1 = customtkinter.CTkFrame(master=app, corner_radius=15)
frame_1.pack(pady=20, padx=60, fill="both", expand=True)
label_1 = customtkinter.CTkLabel(master=frame_1,text_font="caltons", justify=tkinter.LEFT)
label_1.pack(pady=y_padding, padx=10)
progressbar_1 = customtkinter.CTkProgressBar(master=frame_1)
progressbar_1.pack(pady=y_padding, padx=10)
button_1 = customtkinter.CTkButton(master=frame_1, corner_radius=8, command=button_function)
button_1.pack(pady=y_padding, padx=10)
slider_1 = customtkinter.CTkSlider(master=frame_1, command=slider_function, from_=0, to=1)
slider_1.pack(pady=y_padding, padx=10)
slider_1.set(0.5)
entry_1 = customtkinter.CTkEntry(master=frame_1, placeholder_text="CTkEntry")
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(value=1)
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)
s_var = tkinter.StringVar(value="on")
switch_1 = customtkinter.CTkSwitch(master=frame_1)
switch_1.pack(pady=y_padding, padx=10)
optionmenu_1 = customtkinter.CTkComboBox(master=frame_1, values=["option 1", "option 2", "number 42","option 1", "option 2", "number 42","option 1", "option 2", "number 42"])
optionmenu_1.pack(pady=y_padding, padx=10)
app.mainloop()
def Normal_Tkinter():
app = tkinter.Tk()
app.geometry("400x400")
app.title("Standard Tkinter Test")
def button_function():
print("button pressed")
def slider_function(value):
progressbar_1["value"] = value
s = ttk.Style()
s.configure("TRadiobutton", fg="red")
y_padding = 6
frame_1 = tkinter.Frame(master=app, width=300, height=260, bg="lightgray")
frame_1.pack(padx=60, pady=20, fill="both", expand=True)
label_1 = tkinter.Label(master=frame_1, text="Label", bg="lightgray")
label_1.pack(pady=y_padding, padx=10)
progressbar_1 = ttk.Progressbar(master=frame_1, style='black.Horizontal.TProgressbar', length=150)
progressbar_1.pack(pady=y_padding, padx=10)
progressbar_1["value"] = 50
button_1 = tkinter.Button(master=frame_1, command=button_function, text="Button", highlightbackground="lightgray")
button_1.pack(pady=y_padding, padx=10)
slider_1 = tkinter.Scale(master=frame_1, command=slider_function, orient="horizontal", bg="lightgray", length=150)
slider_1.pack(pady=y_padding, padx=10)
entry_1 = tkinter.Entry(master=frame_1, highlightbackground="lightgray", width=10)
entry_1.pack(pady=y_padding, padx=10)
checkbox_1 = tkinter.Checkbutton(master=frame_1, bg=frame_1.cget("bg"), text="CheckButton")
checkbox_1.pack(pady=y_padding, padx=10)
radiobutton_var = tkinter.IntVar()
radiobutton_1 = ttk.Radiobutton(master=frame_1, variable=radiobutton_var, value=1, text="Radiobutton")
radiobutton_1.pack(pady=y_padding, padx=10)
radiobutton_2 = ttk.Radiobutton(master=frame_1, variable=radiobutton_var, value=2, text="Radiobutton")
radiobutton_2.pack(pady=y_padding, padx=10)
combobox_1 = ttk.Combobox(master=frame_1, values=["option 1", "option 2", "number 42","option 1", "option 2", "number 42","option 1", "option 2", "number 42"])
combobox_1.pack(pady=y_padding, padx=10)
app.mainloop()
if __name__ == "__main__":
# Identify the OS
if sys.platform.startswith("linux"):
Normal_Tkinter() # This will link it to the normal tkinter class app
else:
CTK_App() |
Beta Was this translation helpful? Give feedback.
@Free-Radical
Here is an Example