Kiran Kumar Panigrahi

Kiran Kumar Panigrahi

About


312 Articles Published

Articles by Kiran Kumar Panigrahi

Page 2 of 32

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

How to draw a dashed line on a Tkinter canvas?

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

To draw a dashed line on a Tkinter canvas, we can use the dash parameter of the create_line() method. The dash parameter accepts a tuple that defines the pattern of dashes and spaces. Steps Import the tkinter library and create an instance of tkinter frame. Set the size of the frame using geometry() method. Create a Canvas widget and set its height and width. Use the create_line() function and pass the coordinates of the line (x1, y1) and (x2, y2). To get a dashed line, use the dash parameter like dash=(5, 1) for 5px dash followed by ...

Read More

How to align checkbutton in ttk to the left side?

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

To align checkbuttons to the left side in tkinter, you can use the anchor parameter and set it to "w" (west). This ensures that the text and checkbox are positioned to the left within their allocated space. Steps Import the tkinter library and create an instance of tkinter frame. Set the size of the frame using geometry method. Create a LabelFrame to collect the checkbuttons in a group. Create checkbuttons inside the LabelFrame and set their anchor to "w" (west). Use the width parameter to provide adequate space for left alignment. Finally, run the mainloop of the ...

Read More

How to exit from Python using a Tkinter Button?

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

To exit from Python using a Tkinter button, you can use either the destroy() or quit() method. Both methods close the application window, but they work differently under the hood. Steps Import the tkinter library and create an instance of tkinter frame. Set the size of the frame using geometry method. Define a function close() to close the window. Call the method win.destroy() inside close(). Next, create a button and call the close() function. Finally, run the mainloop of the application window. ...

Read More

How to place an image into a frame in Tkinter?

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

To place an image into a Tkinter frame, you need to use the Pillow (PIL) library along with Tkinter. This allows you to load and display various image formats within your GUI application. Required Libraries First, ensure you have the required libraries installed ? pip install pillow Basic Implementation Here's how to create a frame and place an image inside it ? # Import required libraries from tkinter import * from PIL import ImageTk, Image # Create an instance of tkinter window win = Tk() # Define the geometry ...

Read More

Tkinter-How to get the current date to display in a tkinter window?

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

To display the current date in a Tkinter window, we can use Python's built-in datetime module to get the current date and time, then format it for display in a Label widget. Basic Approach The key steps are importing datetime, getting the current date with datetime.now(), and formatting it using strftime format codes ? import tkinter as tk import datetime as dt # Get current date current_date = dt.datetime.now() print(f"Today is: {current_date:%A, %B %d, %Y}") Today is: Wednesday, December 18, 2024 Complete Tkinter Example Here's a complete example that ...

Read More

Creating an automatically maximized tkinter window

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

Tkinter provides several methods to create automatically maximized windows. Two common approaches are using the state() method with "zoomed" attribute and the attributes() method with "-fullscreen" parameter. Method 1: Using state() with "zoomed" The state("zoomed") method maximizes the window while keeping the title bar and window controls visible ? # Import the required libraries from tkinter import * # Create an instance of tkinter frame root = Tk() # Create a label Label(root, text="Welcome to Tutorialspoint", font="Calibri, 20").pack(pady=20) # Maximize the window using state property root.state('zoomed') root.mainloop() Method 2: Using ...

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