Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

About


312 Articles Published

Articles by Kiran Kumar Panigrahi

312 articles

How to stop event propagation in Python Tkinter?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 27-Mar-2026 1K+ Views

Tkinter events are very powerful in handling different objects and widgets in an application. When multiple widgets overlap or are nested, event propagation can cause unintended behavior where clicking one element triggers events for multiple elements. Understanding how to control event propagation is crucial for building responsive GUI applications. In this tutorial, we'll explore how to stop event propagation in Python Tkinter using practical examples with canvas widgets and shape objects. Understanding Event Propagation Event propagation occurs when an event triggered on a child widget also gets passed to its parent widget. For example, clicking a shape ...

Read More

Python: How to update tkinter labels using a loop?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 27-Mar-2026 3K+ Views

We normally use the Tkinter Label widget to display text and images in an application. Let us assume that we want to create an application such that the Label widget continuously gets updated with a value whenever the application executes. To achieve this, we will use a StringVar object and update its value using a loop that will iterate as long as a particular condition satisfies. A StringVar object in Tkinter can help manage the value of a widget such as an Entry widget or a Label widget. You can assign a StringVar object to the textvariable of a ...

Read More

Python: How to put a border around an OptionMenu using Tkinter?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 27-Mar-2026 862 Views

Adding a border around an OptionMenu widget in Tkinter can be achieved using the borderwidth and relief configuration options. These properties control the appearance of the border around the widget. Basic OptionMenu with Border The borderwidth parameter sets the thickness of the border, while relief determines the border style ? import tkinter as tk from tkinter import * # Create an instance of Tkinter frame root = tk.Tk() root.geometry("400x300") root.title("OptionMenu with Border") # Create menu options options = ("Cellphone", "Laptop", "Smartwatch", "Digital Camera") # Create a StringVar to hold the selected value selected_option ...

Read More

How to update a Button widget in Tkinter?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 27-Mar-2026 3K+ Views

We can update a Button widget in Tkinter in various ways, for example, we can change its size, change its background color, or remove its border. The configure() method is the primary way to update button properties after creation. Syntax button.configure(property=value) Common Button Properties Property Description Example text Button text "Click Me" bg Background color "green" font Font style and size ("Arial", 12, "bold") borderwidth Border thickness 0 (no border) state Button state "disabled" Example In the following ...

Read More

How to insert a temporary text in a tkinter Entry widget?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 26-Mar-2026 24K+ Views

To insert a temporary text (placeholder) in a tkinter Entry widget, we can bind the event to clear the placeholder text when the user clicks on the entry field. This creates a user-friendly interface with helpful hints. Basic Implementation Here's how to create a basic placeholder text that disappears when the user focuses on the entry widget ? import tkinter as tk # Create the main window root = tk.Tk() root.geometry("400x200") root.title("Temporary Text Example") def clear_placeholder(event): """Clear placeholder text when entry gets focus""" if entry.get() ...

Read More

How to show the status of CAPS Lock Key in tkinter?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 26-Mar-2026 1K+ Views

We can use the and bindings to check if the CAPS Lock Key is ON or off. In the following example, we will create two user-defined functions "caps_lock_on()" and "caps_lock_off()" which will capture the event of Lock-KeyPress and Lock-KeyRelease and display the status on the screen. Example Here's a complete example that shows the CAPS Lock status using event bindings ? # Import required libraries from tkinter import * # Create an instance of tkinter frame win = Tk() # Define the geometry of the window win.geometry("700x250") win.title("CAPS Lock Status") def ...

Read More

How to call a function using the OptionMenu widget in Tkinter?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 26-Mar-2026 5K+ Views

The OptionMenu widget in Tkinter allows users to select from a dropdown list of options. You can call a function when an option is selected by using the command parameter and a StringVar object to track the selected value. Basic Setup First, create a StringVar object to manage the selected value and define a callback function ? from tkinter import * # Create main window root = Tk() root.geometry("400x300") root.title("OptionMenu Example") # Create StringVar to store selected value selected_city = StringVar() selected_city.set("Select a City") # Define callback function def on_city_select(value): ...

Read More

How to get the longitude and latitude of a city using Python?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 26-Mar-2026 33K+ Views

To get the longitude and latitude of a city, we will use the geopy module. geopy uses third-party geocoders and other data sources to locate the coordinates of addresses, cities, countries, etc. First of all, make sure the geopy module is installed − pip install geopy Using Nominatim Geocoder In the following example, we will use the Nominatim geocoder to find the longitude and latitude of the city "Hyderabad" ? Steps Import Nominatim geocoder from geopy module. ...

Read More

How to use a StringVar object in an Entry widget in Tkinter?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 26-Mar-2026 6K+ Views

A StringVar object in Tkinter helps manage the value of widgets like Entry or Label. You can assign a StringVar object to the textvariable parameter of a widget to dynamically read and update its value. Basic StringVar Usage Here's how to create and use a StringVar with an Entry widget ? from tkinter import * root = Tk() root.geometry("400x200") # Create StringVar object var = StringVar(root) # Create Entry widget with StringVar entry = Entry(root, textvariable=var) entry.pack(pady=10) # Set initial value var.set("Hello World") root.mainloop() Getting and Setting Values ...

Read More

How to set a default string value on a Tkinter Spinbox?

Kiran Kumar Panigrahi
Kiran Kumar Panigrahi
Updated on 26-Mar-2026 3K+ Views

To set a default string value on a Tkinter Spinbox, we will have to use the set method. Let us take an example and see how to create a spinbox with a set of string values and then set a default string. Steps Import the tkinter library and create an instance of tkinter frame. Set the size of the frame using geometry method. Create a set of strings and save it in a variable, data. Next, use the StringVar() constructor to create a StringVar object. ...

Read More
Showing 1–10 of 312 articles
« Prev 1 2 3 4 5 32 Next »
Advertisements