Modern Graphical User Interfaces in Python

NeuralNine
21 Nov 202211:12

Summary

TLDRIn this tutorial, viewers are guided on creating modern graphical user interfaces (GUIs) using Python with the Custom TKinter module. The video contrasts Custom TKinter with the basic TKinter, highlighting the ease of use and modern aesthetics of the former. Key steps include installing the module, setting appearance modes and color schemes, and constructing a sample login system GUI. The presenter demonstrates adding elements like labels, entries, and buttons, and shows how to switch between dark, light, and system modes, as well as different color themes. Examples from the Custom TKinter GitHub repository are also showcased, offering inspiration for building more complex and stylish interfaces.

Takeaways

  • ๐Ÿ˜€ The video teaches how to create modern graphical user interfaces (GUIs) in Python.
  • ๐Ÿ› ๏ธ It utilizes an external Python module called 'custom TKinter' for building the GUIs.
  • ๐Ÿ”ง The process is similar to using the core Python module 'tkinter', but with different class and function names.
  • ๐Ÿ’ป The video demonstrates how to install 'custom TKinter' using pip and import it into a Python script.
  • ๐ŸŽจ It shows how to set the appearance mode (system, dark, or light) and color themes (blue, green, or dark-blue) for the GUI.
  • ๐Ÿ”‘ The tutorial builds a simple login system interface as an example of a modern-looking GUI.
  • ๐Ÿ“ The script covers creating a root element, defining a login function, and adding UI elements like labels, entries, and buttons.
  • ๐Ÿ“ฆ It introduces the use of 'ctk' objects from 'custom TKinter' for creating components like frames, labels, and buttons.
  • ๐Ÿ”„ The video highlights the ease of changing the color scheme and appearance mode at runtime.
  • ๐ŸŒ It encourages viewers to explore the 'custom TKinter' GitHub repository for more examples and inspiration.

Q & A

  • What is the main topic of the video?

    -The main topic of the video is teaching viewers how to build modern-looking graphical user interfaces in Python.

  • Which Python module is used in the video to create graphical user interfaces?

    -The video uses an external Python module called 'custom TKinter' to create graphical user interfaces.

  • What is the difference between 'custom TKinter' and the core Python module 'TKinter'?

    -The difference is that 'custom TKinter' is an external module that offers a more modern look and feel, while 'TKinter' is a core Python module used to build simple and basic graphical user interfaces.

  • How can one install the 'custom TKinter' module?

    -The 'custom TKinter' module can be installed using the command 'pip install customtkinter' in the command line.

  • What are the three appearance modes available in 'custom TKinter'?

    -The three appearance modes available in 'custom TKinter' are 'system', 'dark', and 'light'.

  • What are the color themes that can be set in 'custom TKinter'?

    -The color themes that can be set in 'custom TKinter' are 'blue', 'green', and 'dark-blue'.

  • What is the purpose of the 'login' function in the video's example?

    -In the video's example, the 'login' function is a placeholder that simply prints 'test'. It's meant to be connected to a button to demonstrate the functionality of the graphical user interface.

  • How is the 'remember me' functionality represented in the graphical user interface?

    -The 'remember me' functionality is represented by a checkbox with the text 'remember me' in the graphical user interface.

  • What is the significance of the 'pack' method used in the video?

    -The 'pack' method is used to add widgets like labels, entries, and buttons to the frame within the root element, specifying their padding and alignment.

  • How can the color scheme of the graphical user interface be changed?

    -The color scheme of the graphical user interface can be changed by setting the default color theme using 'customtkinter.set_default_color_theme' with the options 'blue', 'green', or 'dark-blue'.

  • Where can viewers find more examples of 'custom TKinter' interfaces?

    -Viewers can find more examples of 'custom TKinter' interfaces in the GitHub repository of 'custom TKinter' by searching for it on Google.

Outlines

00:00

๐Ÿ’ป Introduction to Building Modern GUIs with Python

The video begins with an introduction to creating modern graphical user interfaces (GUIs) in Python. The presenter announces that they will use an external Python module called 'custom TKinter' to achieve this, which simplifies the process compared to the core Python module 'Tkinter'. The presenter suggests that viewers can refer to a 'Tkinter crash course' on their channel for foundational knowledge, but it's not a prerequisite. The focus is on the ease of use of 'custom TKinter', which is claimed to be similar to 'Tkinter' with minor differences in class and function names. The presenter guides viewers on how to install 'custom TKinter' via pip and import it into their Python scripts. They also explain how to set the appearance mode and color scheme for the GUI, offering options like 'system', 'dark', and 'light' modes, as well as color themes such as 'dark-blue', 'blue', and 'green'.

05:01

๐Ÿ”‘ Constructing a Login System GUI

In this segment, the presenter demonstrates how to build a simple GUI for a login system using 'custom TKinter'. They start by defining the root element and setting its geometry to 500x350 pixels. A basic function for the login is created, which currently just prints 'test', but the presenter notes that this is where the actual login logic would be implemented in a real application. A frame is added to the root to contain all the GUI elements. Labels, entries for username and password, a login button, and a 'remember me' checkbox are created and packed into the frame with specific padding and alignment settings. The presenter also shows how to encode the password entry to hide the input. The focus remains on the GUI's appearance and structure rather than the backend functionality.

10:03

๐ŸŽจ Customizing and Running the Modern GUI

The final part of the video script covers customizing the GUI's appearance and running the interface. The presenter shows how to change the color scheme on the fly to 'green' and switch between 'dark', 'light', and 'system' modes. They also demonstrate how the GUI elements, such as buttons and checkboxes, adapt to these changes. The presenter encourages viewers to explore the 'custom TKinter' GitHub repository for more examples and inspiration. They run a couple of example interfaces from the repository to showcase the capabilities of 'custom TKinter', including a complex UI with labels, buttons, combo boxes, check boxes, radio buttons, and sliders. The video concludes with a call to action for viewers to like, comment, subscribe, and turn on notifications for future videos, thanking them for watching.

Mindmap

Keywords

๐Ÿ’กGraphical User Interface (GUI)

A Graphical User Interface (GUI) is a type of user interface that allows users to interact with electronic devices through graphical icons and visual indicators instead of text-based interfaces. In the context of the video, the presenter is teaching how to build modern-looking GUIs in Python, which is central to the theme of creating visually appealing and user-friendly applications.

๐Ÿ’กPython

Python is a high-level, interpreted programming language known for its readability and็ฎ€ๆดๆ€ง. It is widely used for various applications, including web development, data analysis, artificial intelligence, and more. In the video, Python is the programming language used to demonstrate the creation of GUIs, highlighting its versatility and ease of use for such tasks.

๐Ÿ’กCustom TKinter

Custom TKinter is an external Python module that extends the capabilities of the standard TKinter library, which is used for creating GUIs. The video mentions using Custom TKinter to build modern-looking interfaces with ease, indicating that it offers more contemporary and stylized components compared to the traditional TKinter.

๐Ÿ’กAppearance Mode

In the context of the video, Appearance Mode refers to the visual theme or style of the GUI, such as 'system', 'dark', or 'light'. The presenter demonstrates how to set the appearance mode using Custom TKinter to ensure the GUI's aesthetic aligns with the user's system preferences or a specific design choice.

๐Ÿ’กColor Scheme

A color scheme in GUI design refers to the set of colors used in the interface to create a visually cohesive look. The video script mentions setting a color scheme for the GUI using Custom TKinter, such as 'dark-blue', 'blue', or 'green', to give the application a consistent and appealing color palette.

๐Ÿ’กLogin System

A login system is a security feature that requires users to provide credentials, typically a username and password, to access a system or application. The video uses a login system as an example to demonstrate how to build a GUI with Custom TKinter, showing elements like text entries for username and password, and a login button.

๐Ÿ’กPlaceholder Text

Placeholder text is a hint that appears in an input field to guide the user on what information to enter. In the video, the presenter shows how to set placeholder text in text entry fields for a login system, such as 'username' and 'password', using Custom TKinter, which helps improve user experience by providing clear instructions.

๐Ÿ’กEncoding Input

Encoding input in a GUI refers to the process of transforming user input, such as hiding characters in a password field for security purposes. The video script mentions encoding the input for the password field to ensure that it does not display in plain text, which is a common practice in login systems to protect sensitive information.

๐Ÿ’กRemember Me Checkbox

A 'Remember Me' checkbox is a feature in login systems that allows users to stay logged in or have their credentials saved for future visits. The video includes a 'Remember Me' checkbox in the GUI example, demonstrating how to implement this feature using Custom TKinter, which can enhance user convenience.

๐Ÿ’กMain Loop

The main loop in GUI programming is the event loop that listens for and handles user interactions, such as clicks and key presses. In the video, the presenter mentions 'root.mainloop()', which is the main loop in a TKinter-based application, necessary for running the GUI and making it interactive.

Highlights

Introduction to building modern graphical user interfaces in Python using the custom TKinter module.

Explanation of the similarities and differences between core Python's TKinter and custom TKinter.

Installation of the custom TKinter module using pip.

Setting the appearance mode of the application to system, dark, or light.

Customizing the color scheme with themes like dark-blue, blue, or green.

Creating a basic GUI structure for a login system.

Defining a simple login function that prints a test message.

Adding a frame to the GUI to contain the login elements.

Creating text entries for username and password with placeholder text.

Encoding the password entry for secure input.

Adding a login button and connecting it to the login function.

Including a 'Remember Me' checkbox in the login interface.

Running the GUI to display the modern-looking login interface.

Demonstrating the ability to change the color scheme and appearance mode dynamically.

Providing examples from the custom TKinter GitHub repository to showcase additional UI elements.

Exploring a complex UI example with labels, buttons, combo boxes, checkboxes, radio buttons, and sliders.

Conclusion and call to action for viewers to like, comment, subscribe, and turn on notifications for future videos.

Transcripts

play00:00

what is going on guys welcome back in

play00:02

today's video we're going to learn how

play00:03

to build modern looking graphical user

play00:05

interfaces in Python so let us get right

play00:07

into it

play00:08

[Music]

play00:17

all right so we're going to build modern

play00:18

looking graphical user interfaces in

play00:20

this video today and for that we're

play00:21

going to use an external python module

play00:23

called custom TK inter which is very

play00:25

easy to use if you have already worked

play00:27

with a core python module TK inter which

play00:29

is used to build simple basic graphical

play00:31

user interfaces in core python so

play00:33

without relying on external packages and

play00:36

if you want to learn about TK enter

play00:38

first before watching this video you can

play00:40

go to my channel and check out the TK

play00:41

enter crash course but you can also just

play00:43

watch this video you don't need to

play00:44

understand TK enter first the only thing

play00:47

is that when you know how to build

play00:49

graphical user interfaces with TK enter

play00:51

it's basically the same process with

play00:53

custom TK enter just with slightly

play00:55

different class names and slightly

play00:57

different function names so what we're

play00:59

going to do first is we're going to open

play01:00

up the command line and we're going to

play01:02

say pip install custom

play01:04

TK enter and once the module is

play01:07

installed we're going to go into our

play01:09

python script and we're going to import

play01:11

it so import custom TK enter and just as

play01:15

a reminder here if we're using TK intro

play01:17

what we usually do is we say we have a

play01:19

root element we call it TK enter dot TK

play01:22

and then we Define stuff like label

play01:25

equals TK enter dot label we set it to

play01:29

the root element or we put it inside of

play01:30

the root element then we set some text

play01:33

some font size and all that and then we

play01:34

do label dot pack for example and then

play01:37

we Define buttons and entries and stuff

play01:39

like that and this is how you do it in

play01:41

TK enter now in custom TK enter it's

play01:44

basically the same but instead of saying

play01:45

TK enter.tk you say TK or you say custom

play01:49

TK enter Dot ctk and custom TK enter.ctk

play01:53

label but the rest is essentially the

play01:56

same so we're going to start first by

play01:58

defining some basic parameters we're

play02:01

going to set the appearance mode and

play02:02

we're going to set a color scheme and

play02:04

for that we're going to say custom TK

play02:06

enter dot set appearance mode and here

play02:09

you have three choices you can go with

play02:10

system you can go with dark and you can

play02:13

go with light this is basically the way

play02:15

your application will look if you go

play02:17

with system it's just going to take the

play02:19

setting of the system so my Windows

play02:21

system is set to dark mode so the dark

play02:23

mode will be the default setting for my

play02:25

application but I can also provide the

play02:28

light mode if I want to I'm going to go

play02:29

with dark so that my application always

play02:32

has the dark mode

play02:34

um actually I think it's a lowercase D

play02:37

uh but otherwise you would just pass

play02:39

system uh or light

play02:41

and then I'm also going to say custom TK

play02:44

enter.set default color theme and here

play02:46

we're going to say dark Dash blue in

play02:49

this case you can also set blue and you

play02:52

can also set green so you have blue

play02:54

green and dark blue those are the three

play02:56

themes that you can choose from and now

play02:58

we can just do a very very basic

play03:00

graphical user interface and for this

play03:02

video I'm just going to have the idea of

play03:05

a login system so we're just going to

play03:07

build a simple graphical user interface

play03:08

for a login system maybe you can combine

play03:10

it with one of my recent videos where I

play03:12

show you how to build a secure login

play03:14

system you can connect this graphical

play03:16

user interface to the code from this

play03:18

video if you want to

play03:19

um and what we're going to do here first

play03:20

is we're going to say the root element

play03:22

is going to be custom TK enter Dot ctk

play03:26

and we're going to see that the geometry

play03:29

of the root element is going to be

play03:31

500 times 350 pixels

play03:35

then we're going to Define a simple

play03:37

function for the login now here you can

play03:40

actually Implement an actual login

play03:41

function all I'm going to do here is I'm

play03:43

going to just print

play03:45

um I don't know test or something so

play03:47

this is just going to be some function

play03:49

that we call of course if you're

play03:50

building an actual login system with

play03:52

functionality you would implement the

play03:53

login logic in this case I'm just going

play03:55

to do I'm just going to print test so

play03:57

nothing too special we're just going to

play03:59

connect this function to a button so

play04:01

that we see it works the focus is on the

play04:03

graphical user interface itself and what

play04:06

we want to add here is we want to add a

play04:07

frame into which we're going to put all

play04:10

the stuff so we're going to say custom

play04:11

TK enter dot ctk frame and the master of

play04:15

this element is going to be the root

play04:17

element

play04:18

and then we're just going to say frame

play04:20

dot pack we can also use grid but we're

play04:23

going to use pack and we're going to say

play04:25

that it has a vertical padding of 20 and

play04:29

a horizontal padding of 60.

play04:33

we're going to say fill equals both and

play04:36

we're going to say expand equals true

play04:40

so this is going to be the frame and now

play04:42

we're going to add a label two entries

play04:45

for username password and we're going to

play04:46

add a button as well as a checkbox for

play04:49

remember me into this Frame so we're

play04:52

going to say now first that the label

play04:55

is going to be equal to custom TK enter

play04:58

dot ctk label

play05:00

Master equals frame so not root we're

play05:04

not adding it to root directly we're

play05:06

adding it to the frame which is inside

play05:07

of root

play05:09

um and this the text is just going to be

play05:10

a simple login system

play05:14

and we're going to say the text font is

play05:17

going to be equal to

play05:19

Roboto

play05:21

24. I'm not sure if I actually have this

play05:24

font installed so maybe it's just going

play05:25

to default to another font uh but you

play05:28

can set the font that you like then

play05:29

we're going to say label pack with a

play05:31

padding

play05:33

vertically of 12th and

play05:36

horizontally of 10.

play05:38

and then we can actually I mean we're

play05:40

not going to copy that but I'm going to

play05:42

now add two text entries so the username

play05:44

and the password text entry for that

play05:46

we're going to say entry one is going to

play05:49

be equal to custom TK enter ctk entry

play05:52

Master equals frame

play05:55

the placeholder text so we're not going

play05:57

to use the label for this one we're

play05:58

going to just have a placeholder text

play06:00

that is displayed when we don't have any

play06:02

text inside of that entry this is going

play06:05

to be username

play06:06

and uh that's basically it for this one

play06:10

we're going to then say entryone.pack

play06:13

padding y12 padding x 10 again we're

play06:17

going to copy this now

play06:19

and we're going to say entry 2

play06:25

um we'll have the placeholder text

play06:27

password and we're going to also encode

play06:29

uh the actual input so when you enter

play06:31

your password you don't want to show it

play06:33

in clear text so what we're going to do

play06:34

here is we're going to say show equals

play06:36

and then a star symbol

play06:40

we're going to pack this as well then

play06:42

the button the login button itself will

play06:45

be a custom TK enter ctk button with the

play06:48

master being equal to frame it will have

play06:51

a text

play06:53

which says login and we will connect it

play06:56

to the command to the function login

play06:59

and of course again if you're doing this

play07:01

actually if you're actually building a

play07:03

login system you would implement the

play07:04

logic inside of this login function here

play07:07

so then we're going to say button dot

play07:10

pack as well padding Y is going to be 12

play07:14

padding X is going to be 10. and then

play07:18

finally we're going to say check box

play07:20

is going to be a custom TK enter Dot ctk

play07:24

checkbox

play07:26

the master is going to be the for Ram

play07:29

again the text is going to be remember

play07:31

me or stay locked in or something like

play07:34

that and then we're going to do the same

play07:36

thing check box pack padding y12 padding

play07:40

x 10 and finally root dot main Loop

play07:44

that is it so this is a very simple

play07:47

graphical user interface you can see

play07:48

it's not a lot of lines of code so we

play07:50

just have very repetitive type of

play07:52

defining objects setting text setting

play07:54

certain things and then adding them to

play07:56

the frame and the frame itself is added

play07:58

to the root then we have functions we

play07:59

can connect to buttons using the command

play08:01

keyword but this graphical user

play08:03

interface this is very similar to just

play08:04

writing it in TK intro we can replace

play08:06

custom TK enter here with TK enter and

play08:09

we can replace all these ctk things with

play08:13

the same name without ctk and then we

play08:15

would have a TK enter interface but it

play08:17

wouldn't look like this so if I run this

play08:19

now you can see this looks like a modern

play08:21

UI so this is actually a cool UI we can

play08:25

see we have the button here we can see

play08:26

we have the checkbox here I can write

play08:28

stuff you can see it's also encoded

play08:30

um and we can also change now the color

play08:32

scheme up here so I can go and say make

play08:35

it green

play08:36

I can run this again and you can see now

play08:38

the button is green

play08:39

um here we also have a green check box

play08:41

and we can also make this a light Mode

play08:43

app so I can say light

play08:47

and then you can see this is now in

play08:48

light mode and green so you can play

play08:50

around with that you can also set it to

play08:51

system I think it's is it capital S I'm

play08:55

not sure

play08:57

yeah so it's now system it's dark

play08:59

because my system has the dark mode

play09:00

enabled

play09:02

um but what you can also do is you can

play09:04

go to the GitHub repository of custom TK

play09:06

enter so you can just Google custom TK

play09:08

enter GitHub and you can go to the

play09:10

repository to look at some examples I've

play09:13

downloaded two of them just to show you

play09:14

what's possible it's not too fancy here

play09:16

but a simple example is this one it

play09:18

shows off a couple of elements you can

play09:20

see we have here labels buttons combo

play09:22

boxes where you can choose options with

play09:25

different styles we can also use the

play09:26

check boxes here the radio buttons and

play09:29

we can also use sliders that are

play09:30

connected to other elements

play09:32

so progress Bar connected with the

play09:34

slider so we have in this uh code that

play09:38

is provided in the GitHub repository you

play09:40

can see that the slider has a command

play09:43

which is a slider callback the slider

play09:45

callback sets the progress BAR value to

play09:48

the slider value so that's quite simple

play09:50

thing

play09:52

um and then we also have a complex UI so

play09:54

we can run this as well this is also

play09:55

from the examples and you can see that

play09:58

this looks just way more modern and way

play10:00

more interesting than the

play10:03

um the basic TK inter style I think you

play10:05

can easily make the TK inter style like

play10:07

that but you would have to do everything

play10:08

manually this is by default a modern

play10:11

looking graphical user interface so we

play10:13

can see here we can switch the modes

play10:14

dark light system would stay dark

play10:17

obviously

play10:19

um I don't think we can change the color

play10:21

theme Here

play10:23

but you can see how it works you can see

play10:25

how all these elements look and I think

play10:28

we should be able to set this to Green

play10:31

and then we see a green UI if you prefer

play10:33

that

play10:35

so yeah this is how you build modern

play10:36

looking graphical user interfaces in

play10:39

Python so that's it for today's video I

play10:41

hope you enjoyed it and hope you learned

play10:42

something if so let me know by hitting a

play10:44

like button and leaving a comment in the

play10:45

comment section down below and of course

play10:47

don't forget to subscribe to this

play10:48

Channel and hit the notification Bell to

play10:50

not miss a single future video for free

play10:52

other than that thank you much for

play10:53

watching see you in the next video and

play10:54

bye

play11:03

thank you

play11:08

[Music]

Rate This
โ˜…
โ˜…
โ˜…
โ˜…
โ˜…

5.0 / 5 (0 votes)

Related Tags
Python ProgrammingGUI DevelopmentCustom TKinterCoding TutorialDark Mode UILogin SystemWeb DevelopmentUser InterfaceProgramming TipsOpen Source