Javatpoint Logo
Javatpoint Logo

Create a Modern login UI using the CustomTkinter Module in Python

Introduction

In this tutorial, we will discuss how to create a Modern login UI using the CustomTkinter module in Python. Contemporary pc packages are consumer-friendly. Consumer interaction is not limited to console-based totally I/O. They have a different ergonomic graphical person interface (GUI) way to excessive velocity processors and powerful graphics hardware. Those applications can get hold of inputs via mouse clicks and may permit the purchaser to pick out alternatives with the help of radio buttons, dropdown lists, and different GUI factors (or widgets). Such packages are advanced by considering one of the numerous pics libraries available. A photographs library is a software program toolkit having a set of lessons that outline the capability of various GUI elements. These pix libraries are usually written in C/C++. Many of them had been ported to Python as importable modules. Some of them are listed underneath:

Tkinter is the Python port for the Tcl-Tk GUI toolkit superior via Fredrik Lundh. This module is bundled with elegant distributions of Python for all platforms. CustomTkinter is a module this is, in basic terms, built upon the Tkinter module, which enables the builders to create present-day UI, which became no longer feasible with the traditional Tkinter module. It helps various new, contemporary, and customizable widgets to install our UI. Tkinter and CustomTkinter can both be used collectively to construct UI.

Which Module is needed?

In this text, we want a CustomTkinter and Tkinter module to construct the login web page. We will install these modules by executing the below instructions in the terminal.

The way to create a simple blank UI?

To create a simple page first, import the CustomTkinter module, then use the set_appearance_mode() function to darken the appearance of this page and the set_default_color_theme() function to set a blue theme. After that, initialize the app and set the size and title.

Program Code:

Now we write code in python.

Output:

Create a Modern login UI using the CustomTkinter Module in Python

Now we compile the above application and run it. The title bar displays the specified title. In other words, a modern login UI using Customtkinter. It was like this because it was dark mode. Nothing has been added yet, so this topic needs to be reflected. Adding a widget later will take effect. Then the output is given below.

Create the login function:

Here, we write the login function. After getting into an appropriate username and password, a welcome or error message will be displayed. I did not use a database for this, so I used the predefined username and password.

Program Code:

Here, we write a code to create the login function in python. The code is given below -

Here we first create a predefined username and password that can only be used for login. The new_window variable uses the CTkToplevel() method to create another window. This is similar to his Toplevel() method in classic Tkinter. As a parameter, pass the app variable that initialized the CustomTkinter. The new window's title and height, and width are also defined. Then use the get() method to check if the user is passing the correct username and password. The user_entry and user_pass variables will be used later in the code when creating these widgets.

A different warning or error message is displayed for each type of error. Here we also use the traditional Tkinter module's messagebox method to display warning, error, and success messages.

Create and add the widgets in python:

Firstly, we are creating the label of the principle page (it is non-obligatory to present). Then creating the body to create the frame of our UI. Then create the label so one can be proven on the top of the widgets we can add. Then we are growing the access section in which the person will put the username and password; inside the password segment, we are passing the show parameter with "*" because while we enter the password simplest "***" may be shown. Then choosing the padding. Then the Login Button, passing the login function we created earlier, and finally, a checkbox for do not forget me, a consumer might also or might not offer this. Ultimately, we're going for walks with the app using the mainloop() method.

Program Code:

Here, we write code for creating and adding the widgets in python. The code is given below -

Output:

Create a Modern login UI using the CustomTkinter Module in Python

Program Code:

Here, we write the complete code in python. The code is given below -

Basic application of the UI:

GUI factors and their capability are defined within the Tkinter module. The following code demonstrates the stairs to growing a UI.

Explanation:

First, import the TKinter module. After importing, call the Tk() function to set up the application object. This creates a bordered pinnacle-degree (root) window with a title bar, a manipulated field with reduce and close buttons, and a customer vicinity to hold other widgets. The geometry() approach determines the width, height, and coordinates of the upper left nook of the frame as shown beneath (all values are in pixels): window.geometry("widthxheight+XPOS+YPOS"). It loops by calling the mainloop() method. The application now continuously waits for any event generated by the inner element. An event can be text entered into a text field, a selection from a drop-down list or radio button, a single or double-click action, and so on. A function of an application may include executing an appropriate call back function in response to a specific type. Included. of the event. Event handling is discussed later in this tutorial. Click the close button inside the identify bar to exit the event loop.

Conclusion:

So, in this article, we are discussing how to create a Modern login UI using the CustomTkinter module in Python. CustomTkinter is a module this is, in basic terms, built upon the Tkinter module, which enables the builders to create present day UI, which became no longer feasible with the traditional Tkinter module. Contemporary pc packages are consumer-friendly. Consumer interaction is not limited to console-based totally I/O. They have a different ergonomic graphical person interface (GUI) way to excessive velocity processors and powerful graphics hardware.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA