Enhancing Your GUI with customtkinter in Tkinter

Posted by


Tkinter is a popular python library for creating graphical user interfaces (GUI) and applications. It is known for its simplicity and ease of use, but one common complaint about Tkinter is its limited styling options. With the introduction of customtkinter, an extension of Tkinter with better styling capabilities, you can now create more visually appealing and modern-looking GUIs.

In this tutorial, we will walk through the process of setting up customtkinter in your Python environment and explore some of the styling options it offers.

Step 1: Installing customtkinter

The customtkinter library is not included in the standard library of Python, so you will need to install it separately. You can do this by using pip, the package installer for Python. Open your command prompt or terminal and type the following command:

pip install customtkinter

This will download and install the customtkinter library in your Python environment.

Step 2: Importing customtkinter in your code

Now that you have installed the customtkinter library, you can start using it in your code. To import customtkinter, add the following line at the beginning of your Python script:

from customtkinter import *

This will import all the classes and functions from the customtkinter library, allowing you to use its styling options in your GUI.

Step 3: Creating a custom styled button

One of the key features of customtkinter is its ability to create custom-styled widgets, such as buttons, labels, and entry fields. Let’s start by creating a custom-styled button using customtkinter. Here’s an example code snippet:

from customtkinter import *

root = Tk()

button = CustomButton(root, text="Click me", bg="blue", fg="white", font=("Arial", 12), width=10, height=2)

button.pack(pady=20)

root.mainloop()

In this code snippet, we created a custom button widget using the CustomButton class from customtkinter. We specified the text, background color, foreground color, font, width, and height of the button. Finally, we packed the button into the root window and started the main event loop.

Step 4: Exploring more styling options

Customtkinter offers a wide range of styling options for customizing the appearance of your GUI widgets. Some of the styling options you can explore include:

  • Setting the border width and color of widgets
  • Adding images or icons to widgets
  • Customizing the padding and spacing of widgets
  • Changing the text alignment and styling
  • Applying gradients and animations to widgets

You can experiment with these styling options to create unique and visually appealing GUIs for your applications.

Step 5: Conclusion

In this tutorial, we introduced customtkinter, a library that extends the styling capabilities of Tkinter for creating modern-looking GUIs. We walked through the process of installing customtkinter, importing it into your code, creating custom-styled widgets, and exploring various styling options.

By using customtkinter, you can take your GUI design to the next level and create visually stunning applications that stand out from the crowd. Give customtkinter a try in your next project and see the difference it makes in the appearance of your GUI.

0 0 votes
Article Rating
28 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@Mark-yg8oe
1 month ago

Awesome tutorial!!! Is there a way to change the window image next to the window title?

@c-ronos
1 month ago

great tutorial.

@kench1
1 month ago

TypeError: CTkSwitch.__init__() missing 1 required positional argument: 'master' what does the mast argument do?

switch = ctk.CTkSwitch(window, text="CTkSwitch", command=switch_event,
variable=switch_var, onvalue="on", offvalue="off") but still says there is not master

nvm i got it i was being a silly boy

@janlochman1985
1 month ago

It would be nice if it had cross-platform support. As for now, it's ugly on Linux-like systems, and looking at Github doesn't give you hope that it will change. Even some people report issues with certain types of Windows. So, developing a cross-platform app in Customtkinter would ruin it.

@gregcrawford6059
1 month ago

Good tutorials.

But how do you get rounded corners on the widgets without seeing the white background.
With windows 10 I only see the full affect of rounded corners when appearance is set to light. When it's dark then the widgets always show the corners as white.

@Norcuck
1 month ago

how to make colored text with ctk label, like first half red second half blue?

@dheerparekh1305
1 month ago

the powershell says that 'pip' is not recognized , what to do

@rafortwalfer
1 month ago

Bro! do you know How to set Favicon at place of CTkinter logo

@RFBPekopon
1 month ago

where was the api for CTk that you were showing?

@LuaExplained
1 month ago

what exactly are you coding this in?

@pilyotuts
1 month ago

theres no labelframe?

@Nestorhnz
1 month ago

Great tutorial bro, thanks

@samarthvyas8234
1 month ago

how can we change icon in Customtkinter??

@tha3dudes
1 month ago

How come code can run well the first 10 times you execute them and than all of the sudden it gives you a
SyntaxError: invalid syntax?
The code in question is:
switch=ctk.CTkSwitch(window,

text="Excercise switch",

fg_color="red",

progress_color="white",

button_color="light blue"

command=lambda:ctk.set_appearance_mode=("dark"))

switch.pack()

error is command=lambda:ctk.set_appearance_mode=("dark"))
When I remove this it will say the error is
switch.pack()
anyone able to help me out it worked fine when I first wrote and tested it…..

@gilleslejeune6823
1 month ago

Thanks, but in customtkinter there is no treeview and listbox ?

@sonu-jangir
1 month ago

Thank you so much sir for your all awesome videos…❤🎉

@SouthSaharaMedia
1 month ago

wow … this was easier to understand

@giomacale8045
1 month ago

hello is there a way we can set ctk as fullscreen?

@rupaksaha9050
1 month ago

My window isn't black, even if I use .configure

@kvjrey
1 month ago

its good, but I noticed it feels not complete