Gaurav Leekha

Gaurav Leekha

115 Articles Published

Articles by Gaurav Leekha

Page 2 of 12

Get the ID of a widget that invoke an event in Tkinter

Gaurav Leekha
Gaurav Leekha
Updated on 02-Apr-2026 2K+ Views

Tkinter provides a mechanism to bind events to widgets. When an event occurs, such as a button click or mouse movement, a specific function or method associated with that event is executed. The event handler function typically takes an event object as a parameter, which provides information about the event. While the event object does not directly include the ID of the widget, we can use various techniques to identify the widget based on the event. In this article, let's explore these approaches. Using winfo_id() Method The most direct approach is to use the winfo_id() method on the ...

Read More

Enable multiple selection of values from a Tkinter Combobox

Gaurav Leekha
Gaurav Leekha
Updated on 02-Apr-2026 6K+ Views

Tkinter is a powerful GUI toolkit for creating desktop applications in Python. The Combobox widget normally allows only single selection, but there are scenarios where multiple selection is needed. This article explores two approaches to enable multiple selection functionality. Using the Listbox Widget The simplest approach is to combine a Combobox with a Listbox widget. The Listbox displays selectable options, while the Combobox shows the selected values. Example Here's a complete implementation using the Listbox approach − import tkinter as tk from tkinter import ttk # Create main window window = tk.Tk() window.geometry("400x350") ...

Read More

Displaying up to date input signals with tkinter GUI

Gaurav Leekha
Gaurav Leekha
Updated on 02-Apr-2026 504 Views

Creating a responsive and real-time user experience in a Tkinter GUI relies on accurately and promptly displaying input signals. Whether it's user interactions or data from external sources, keeping the GUI up-to-date with the latest input is crucial for an intuitive and interactive interface. In this article, we will explore techniques to achieve this goal by leveraging Tkinter's event-driven architecture and updating strategies. By registering event handlers and updating the GUI components dynamically, developers can ensure that the interface reflects the current state of input signals. This allows for seamless user interactions, real-time data visualization, and effective monitoring ...

Read More

Displaying images from url in tkinter

Gaurav Leekha
Gaurav Leekha
Updated on 02-Apr-2026 3K+ Views

Displaying images in Tkinter GUI applications can greatly enhance the visual appeal and user experience. While Tkinter provides various tools for working with images, displaying images directly from a URL requires additional steps. In this article, we will explore how to fetch and display images from URLs in Tkinter using the Python Imaging Library (PIL). We'll learn how to handle URL requests, process the image data, and showcase the images within Tkinter windows. Installing PIL Library To display images from a URL in Tkinter, we need to use the PIL (Python Imaging Library) library. It provides powerful image ...

Read More

Determine which Tkinter widget is on top or visible

Gaurav Leekha
Gaurav Leekha
Updated on 02-Apr-2026 763 Views

Tkinter is a popular Python library used for creating graphical user interfaces (GUIs). When developing GUI applications, it is crucial to determine which widget is on top or visible to implement specific functionality or handle user interactions. This article explores various techniques and provides Python examples to help you identify the top or visible Tkinter widget in your application. Understanding Widget Hierarchy in Tkinter Before we begin, it's essential to grasp the concept of the widget hierarchy in Tkinter. Tkinter uses a tree-like structure to organize widgets, with the root window serving as the parent for all other ...

Read More

Creating a wizard in Tkinter

Gaurav Leekha
Gaurav Leekha
Updated on 02-Apr-2026 1K+ Views

Tkinter, the standard GUI toolkit for Python, provides a robust foundation for creating graphical user interfaces. A wizard, in the context of a Tkinter application, typically involves multiple steps or pages that guide users through a specific workflow. The user navigates through these steps using "Next" and "Back" buttons until they reach the final step. In this article, we'll explore the creation of a simple three-step wizard using Tkinter. Each step is represented by a distinct frame, and we'll implement navigation logic to move between wizard steps seamlessly. Understanding the Wizard Structure A wizard typically consists of ...

Read More

Create autohide Tkinter canvas scrollbar with pack geometry

Gaurav Leekha
Gaurav Leekha
Updated on 02-Apr-2026 929 Views

Tkinter provides a versatile set of tools for building graphical user interfaces. When working with large amounts of content in a Canvas widget, implementing auto-hide scrollbars enhances user experience by appearing only when needed, providing a clean and uncluttered interface. Concept of Auto-Hide Scrollbars Auto-hide scrollbars dynamically adjust visibility based on content size. They appear only when content exceeds the visible canvas area, optimizing screen space and reducing visual distractions. The pack geometry manager allows straightforward organization of widgets, making it ideal for implementing this functionality. Setting up the Canvas and Scrollbars First, we create a ...

Read More

Playing a Beep Sound in Python: winsound Module

Gaurav Leekha
Gaurav Leekha
Updated on 27-Mar-2026 4K+ Views

The Python winsound module is a simple way to play audio files and generate beep sounds on Windows machines. It provides a straightforward interface for playing sound files, generating system beeps, and working with MIDI devices using just a few lines of code. The winsound module is part of the Python standard library, so you don't need to install it separately. While it has some limitations such as only supporting a limited number of audio file formats and being Windows-specific, it can be a useful tool for simple audio tasks in Python. In this tutorial, we'll explore how ...

Read More

Choropleth maps using Plotly in Python

Gaurav Leekha
Gaurav Leekha
Updated on 27-Mar-2026 1K+ Views

A choropleth map is a map that displays data on geographic regions using different colors or shades to represent values. The data is usually represented as a color scale, with darker colors indicating higher values and lighter colors indicating lower values. Choropleth maps are useful for visualizing data on a map, such as demographic data, election results, or economic indicators. Plotly is a Python data visualization library that allows users to create interactive plots and charts. It offers a range of features for creating custom visualizations, including line charts, scatterplots, bar charts, and choropleth maps. In this tutorial, we ...

Read More

Choose element(s) from List with different probability in Python

Gaurav Leekha
Gaurav Leekha
Updated on 27-Mar-2026 2K+ Views

An important aspect of creating accurate simulations is the ability to choose elements from a list with different probabilities. For example, in a simulation of a crowd, certain actions may be more likely to occur than others, or in a simulation of a physical system, particles may move with different probabilities in different directions. Python provides several ways to choose elements from a list with different probabilities. In this tutorial, we'll explore different techniques using the built-in random module and the NumPy module. Choosing Elements with Equal Probability Let's first discuss how to choose elements from a ...

Read More
Showing 11–20 of 115 articles
« Prev 1 2 3 4 5 12 Next »
Advertisements