Enhance Tkinter: CustomTkinter for 10x Better Interface

This article is a summary of the YouTube video ‘Make Tkinter Look 10x Better in 5 Minutes (CustomTkinter)’ by TurbineThree

Written by: Recapz Bot

Written by: Recapz Bot

AI Summaries of YouTube Videos to Save you Time

How does it work?
Custom tkinter is a tkinter-based package for customized application widgets, offering various styling options, layouts, and functionality, with documentation, examples, and additional resources provided.

Key Insights

  • The video explains how to customize tkinter applications using the custom tkinter package.
  • Custom tkinter is built on top of tkinter and provides common widgets with extra styling options.
  • The ctk class is used to create a window and it has the same functions as tkinter.
  • The ctk button class provides buttons with the ability to use layout functions like pack, place, and grid.
  • Styling options for buttons include changing the corner radius, colors, border color, and width.
  • Buttons can also have icons by saving them as images and using the ctk image class.
  • The label widget is used for displaying text and can have custom fonts, sizes, and colors.
  • The combo box widget is used for drop-down selection, with customizable foreground, border, and drop-down colors.
  • The checkbox widget offers different options with configurable colors, size, and roundness.
  • The switch widget provides toggleable options similar to checkboxes.
  • The slider widget allows users to select values by dragging, with options to determine start and end values, number of steps, and custom colors.
  • Text input can be achieved using the entry widget, specifying placeholder text, size, and color.
  • For larger text input, the textbox widget offers scrollable text fields with customizable scroll bars, corner radius, and borders.
  • Documentation is available with all widget properties and information.
  • Events like button clicks can be handled using the command parameter and specifying a function.
  • Text input can be retrieved using the get method, with the ability to specify start and end indexes for a textbox.
  • The configure method can be used to change widget properties within functions.
  • Frames can be used as containers to separate widgets, with customizable colors and borders.
  • Scrollable frames can be used for vertical and horizontal scrolling, with customizable scroll bars.
  • Tab views allow for organizing widgets in different tabs, with the ability to add tabs and specify the master for widgets.
  • The setDefaultColorTheme function allows for quick color changes of all widgets, with pre-defined color themes.
  • Custom color themes created by others can also be used.
  • Example applications created using custom tkinter widgets are provided.
  • Links to code and resources are available in the video description.

Seedless Grapes: Are They GMOs?

Annexation of Puerto Rico: ‘Little Giants’ Trick Play Explained

Android Hacking Made Easy: AndroRAT Tutorial

Andrew Huberman’s Muscle Growth and Strength Workout Plan

AMG Lyrics – Peso Pluma

Alex Lora: Rising Passion

Transcript

This is how normal tkinter applications look like, and in this video, I’ll show you how to turn them into this with the custom tkinter package and a few minor tweaks to your code. Install it by running pip install custom tkinter, import it, and let’s get started.

Custom tkinter is built on top of tkinter, so it contains all the common widgets you expect with some extra styling. To start, the window can be created using the ctk class. This has all the same functions as the one in tkinter, so you can resize it and run the main loop to launch the window using the same functions.

Now that we have a window, what can we put in it? The most common widget is a button. Custom tkinter provides this under the ctk button class. Here we can use the same layout functions with other tkinter widgets, which are pack, place, and grid. There’s some styling by default, but you can change things like the corner radius, which determines how rounded the corners are, and the colors for the foreground/hovered state.

Right now, my app is in dark mode based on my system settings, but if you want to toggle between dark and light mode, you can set the appearance mode manually, and the widgets will update to match.

To give the button a border, we can set the border color and border width. We can also set the foreground to transparent to make it an outline button. If you want to give the button an icon, save it as an image and open it using Pillow by importing the image class. Pillow is a package used to process images, and if you don’t have it installed, you’ll need to run this command. We can then set it as an image using the ctk image class, where we can specify different versions for the light and dark mode.

For displaying text, there’s also the label widget, which works just like the one in tkinter. Here, you can specify any font that you have installed, alongside the font size and a tuple. The text color can also be changed using the text color property.

Another common user interaction is to provide the drop-down selection. For that, there is the combo box widget, where you can pass in the values displayed in the drop-down menu. Here, you can change the foreground, border, and drop-down colors.

Speaking of options, we also have the checkbox widget to provide a selection of different options. The colors, size, and roundness can all be configured here as well. Similar to using checkboxes, you can also create a switch widget if you want to have toggleable options.

For user input, which are numbers, there’s the slider widget, which lets the user drag to select a value. You can change the start and end values, as well as the number of steps. The button color, progress color, and orientation are also customizable.

But what about text input? For that, we have the entry widget, and you can specify things like the placeholder text, size, and text color. But what if you need a larger text input field? There’s the textbox widget, which provides a scrollable text field spanning multiple lines. The scrollbar, corner radius, and border are all customizable here.

If you want a reference for all the properties for each widget, you can find all the information in the documentation, which I’ll link below.

Now that we have widgets in our window, how do we handle events like button clicks? Just like in tkinter, we can use the command parameter on the widget and specify a function which is then called when the input widget is clicked on. And as for widgets like the combo box and the slider, the function also receives the value that the user has selected.

Next up, to retrieve text input, we need to use the get method on the widget. The value will be whatever the user has currently entered when the method is called. And if you’re trying to get a value from a textbox, you need to specify the start and end index of the text that you want to retrieve. Here, I’ve selected everything, which is usually what you want to do.

Besides that, to change properties on widgets within functions, we can also use the configure method. This allows us to specify any property as a parameter and give it its new value.

Moving on to creating different sections in your interface, we can make use of frames to separate our widgets. The frame widget acts like a container and can be customized with its color and border. To use it, we just need to specify it as a master for the widgets that should be placed inside of it. If you have more widgets and want to make the frame scrollable, use a scrollable frame, which can be used for both vertical and horizontal scrolling and which has a customizable scrollbar as well.

Besides using frames, you can also store your widgets in different tabs, similar to having tabs in the browser. For that, we will need to create an instance of ctkTabView and add tabs to it using the add method, where “this” is the name for the tab. When you want to add widgets to a specific tab, you then need to specify the master as the same tab name like so.

We saw that the widgets cannot be customized with specific colors, but what if you wanted to quickly change their colors all at once? The setDefaultColorTheme function provides this functionality. You can choose from blue, green, or dark blue to quickly change the colors of all widgets. There are also custom color themes made by others, which you can find in the link below. Simply choose one, download it, and set the color theme as the JSON file, which contains all the color codes.

Now that we’ve seen the widgets and styling custom tkinter provides, here are some examples of applications that I’ve quickly made using the widgets from custom tkinter that we went over in this video. Some of them use a few extra packages, such as tables made by other developers that you can install separately. I’ll leave the links to all of the code for them below as well.

That’s custom tkinter in 5 minutes. Watch this video next if you’re interested in Python GUIs. Besides that, consider liking this video and subscribing if it has helped.

This article is a summary of the YouTube video ‘Make Tkinter Look 10x Better in 5 Minutes (CustomTkinter)’ by TurbineThree