Dev Prakash Sharma

Dev Prakash Sharma

414 Articles Published

Articles by Dev Prakash Sharma

Page 14 of 42

How to add a margin to a tkinter window?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 8K+ Views

In tkinter, you can add margins to windows and widgets using several approaches. The most common methods involve the pack() geometry manager with padx and pady parameters, or the grid() geometry manager with padding options. Using pack() with Padding The pack() method allows you to add margins using padx (horizontal) and pady (vertical) parameters − # Import the required library from tkinter import * # Create an instance of tkinter frame win = Tk() # Set the size of the Tkinter window win.geometry("700x350") # Add a frame to set the margin of the ...

Read More

How do you create a Tkinter GUI stop button to break an infinite loop?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 2K+ Views

Tkinter is a Python library used to create GUI-based applications. Sometimes you need to create a loop that continuously updates the interface, like displaying text or processing data. To control such loops, you can use a global variable with Start and Stop buttons. The key is using win.after() instead of a traditional while loop, which would freeze the GUI. This method schedules function calls without blocking the interface. Example Here's how to create a controllable loop with Start and Stop buttons − # Import the required library from tkinter import * # Create an ...

Read More

Python Tkinter – Set Entry width 100%

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 3K+ Views

Tkinter Entry widgets accept single-line user input in a text field. We can change the properties of the Entry widget by providing the default attributes and values in its constructor. When creating GUI applications, you often need Entry widgets that span the full width of the container. The Pack geometry manager provides several ways to achieve this using the fill parameter. Using fill='x' Parameter The simplest way to create a full-width Entry widget is using the fill='x' parameter with the pack method ? # Import the required library from tkinter import * from tkinter import ...

Read More

How to create hyperlink in a Tkinter Text widget?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 5K+ Views

Tkinter Text widgets are generally used for accepting multiline user input in the given text field. For a particular text document, the content may contain hyperlinks too which is useful in case we want to redirect the user. You can create hyperlinks within the text widget by using HyperLinkManager snippet in Python. The HyperLinkManager code snippet adds the hyperlink on the keyword within the text widget and handles click events to open URLs in the default web browser. HyperlinkManager Class First, we need to create the HyperlinkManager class that handles hyperlink functionality ? import tkinter ...

Read More

Using OpenCV with Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 8K+ Views

OpenCV is a Python library used for computer vision and image processing tasks. Combined with Tkinter, you can create interactive GUI applications that capture and display video frames from your webcam in real-time. Installation Requirements Before creating the application, install the required packages − pip install opencv-python pip install Pillow How It Works The application uses OpenCV to capture video frames from your webcam. Each frame is converted using PIL (Pillow) into a format that Tkinter can display. The frames are continuously updated in a Label widget to create a live video feed. ...

Read More

What is a better Tkinter geometry manager than .grid()?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 496 Views

The Geometry Manager is one of the specific features in the Tkinter library that provides structure to all Tkinter widgets in the window. It controls the formatting, layout and positioning of widgets in a Tkinter application. Tkinter offers three geometry managers, each with unique strengths ? Pack Geometry Manager − Simple linear arrangement Grid Geometry Manager − Table-like rows and columns Place Geometry Manager − Absolute positioning Pack Geometry Manager The pack() method is the simplest geometry manager, ideal for basic layouts. It arranges widgets in blocks before placing them in the parent widget. ...

Read More

Inheriting from Frame or not in a Tkinter application

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 1K+ Views

In Object-Oriented Programming, inheritance allows a derived class to acquire properties from a base class. In Tkinter applications, you can inherit from the Frame class to create custom frames with predefined properties like background color, dimensions, and styling. When you inherit from Frame, your custom class automatically gains all Frame capabilities while allowing you to define default properties that will be applied to every instance. Example: Inheriting from Frame Here's how to create a custom frame class by inheriting from Tkinter's Frame ? # Import Tkinter Library from tkinter import * # Create an ...

Read More

Creating scrollable Listbox within a grid using Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 4K+ Views

A Listbox widget displays a list of items such as numbers, employee names, or any collection of data. When dealing with long lists, we need scrollbars to navigate through all items effectively. By attaching a Scrollbar to a Listbox and configuring them properly, we can create a scrollable interface within a grid layout. Basic Scrollable Listbox Let's start with a simple scrollable Listbox containing numbers from 1 to 100 − # Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of Tkinter Frame win = Tk() win.title("Scrollable Listbox ...

Read More

Call a Function with a Button or a Key in Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 12K+ Views

In Tkinter applications, you can call functions when buttons are clicked or keys are pressed. This is achieved using the command parameter for buttons and the bind() method for key events. Calling a Function with Button Click The simplest way to call a function is by using the command parameter when creating a button ? # Import the required libraries from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of Tkinter Frame win = Tk() # Set the geometry of Tkinter Frame win.geometry("700x350") # Define a ...

Read More

How to clear Text widget content while clicking on the Entry widget itself in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 5K+ Views

The Tkinter Text widget is an input widget that supports multiline user input, functioning as a text editor. You can clear its content using the delete(0, END) method. Similarly, you can clear an Entry widget's content by clicking on it, achieved by binding a function to a click event. Example Here's how to create an Entry widget that clears its placeholder text when clicked ? # Import the required libraries from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry of Tkinter Frame win.geometry("700x250") # ...

Read More
Showing 131–140 of 414 articles
« Prev 1 12 13 14 15 16 42 Next »
Advertisements