Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

About


312 Articles Published

Articles by Kiran Kumar Panigrahi

312 articles

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

How to draw a line following mouse coordinates with tkinter?

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

To draw a line following mouse coordinates in tkinter, we need to capture mouse click coordinates and draw lines between consecutive points. This creates an interactive drawing experience where each click connects to the previous point. Steps Import the tkinter library and create an instance of tkinter frame. Set the size of the frame using geometry method. Create a user-defined method "draw_line" to capture the x and y coordinates of each mouse click. Then, use the create_line() method of Canvas to draw a line between two consecutive points. Bind the left-click of the mouse with the draw_line ...

Read More

How to place the text at the center of an Entry box in Tkinter?

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

To place text at the center of an Entry widget in Tkinter, use the justify parameter with the CENTER value when creating the Entry widget. This centers the text horizontally within the input field. Syntax Entry(parent, justify=CENTER, other_options...) Parameters justify − Controls text alignment. Values: LEFT (default), CENTER, RIGHT width − Width of the Entry widget in characters font − Font family, size, and style for the text bg − Background color of the Entry widget Example Here's how to create an Entry widget with centered text − ...

Read More

How to put a border around a Frame in Python Tkinter?

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

To put a border around a Frame in Tkinter, we can use the highlightbackground and highlightthickness parameters while creating the Frame. Alternatively, we can use relief and borderwidth options for more border styles. Method 1: Using highlightbackground and highlightthickness The highlightbackground parameter sets the border color, while highlightthickness controls the border width ? from tkinter import * root = Tk() root.geometry("400x300") root.title("Frame Border Example") # Create frame with blue border frame1 = Frame(root, highlightbackground="blue", highlightthickness=2) frame1.pack(padx=20, pady=20, fill="both", expand=True) # Add some widgets inside the frame Label(frame1, text="Music Player", font=("Arial", 14, "bold")).pack(pady=10) ...

Read More

Display the Host Name and IP Address on a Tkinter Window

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

To obtain a user's IP address, we can use Python's native networking interface, socket. First of all, we need to query the device's host name and then get its associated IP address. In this example, we will use the socket library to get the host name and IP address and display the details on two labels in a Tkinter window. Steps Import the tkinter library and create an instance of tkinter frame. Set the size of the frame using geometry method. Next, use the gethostname() method of socket library to ...

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