Dev Prakash Sharma

Dev Prakash Sharma

414 Articles Published

Articles by Dev Prakash Sharma

Page 2 of 42

How to bind all the number keys in Tkinter?

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

While developing a Tkinter application, we often encounter cases where we have to perform specific operations or events with keystrokes on the keyboard. Tkinter provides a mechanism to deal with such events through key binding. You can use bind(, callback) function for each widget to bind keys and perform certain types of events. Whenever we bind a key with an event, the callback function executes when the corresponding key is pressed. Syntax widget.bind(key_sequence, callback_function) Where: key_sequence − The key or key combination to bind (e.g., "1", "2", etc.) callback_function − Function to execute ...

Read More

How to make specific text non-removable in tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2026 321 Views

In Tkinter, users can input text using two basic text input widgets − the Text widget and the Entry widget. The Text widget is generally used to accept multiline user input, whereas in an Entry widget, the user can type only single-line text. You can customize these widgets and add additional functionality using built-in library functions and methods. To make specific text non-removable, you can use input validation with the register() method and validation commands. Understanding Validation Parameters To validate input in an Entry widget, use the config(**options) method and pass the validate and validatecommand arguments ? ...

Read More

How to show multiple Canvases at the same time in Tkinter?

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

The Canvas widget in Tkinter is a versatile widget used to create illustrations, draw shapes, arcs, images, and complex layouts. You can display multiple canvases simultaneously using different approaches like separate windows, frames, or grid layouts. Method 1: Multiple Canvases in the Same Window The simplest approach is to create multiple canvas widgets within the same main window ? import tkinter as tk # Create main window root = tk.Tk() root.title("Multiple Canvases") root.geometry("600x400") # Create first canvas canvas1 = tk.Canvas(root, width=200, height=150, bg="lightblue") canvas1.grid(row=0, column=0, padx=10, pady=10) canvas1.create_text(100, 75, text="Canvas 1", font=("Arial", 14, "bold")) ...

Read More

Getting the Cursor position in Tkinter Entry widget

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

In Tkinter Entry widgets, each character position is indexed starting from 0. You can retrieve the current cursor position using the index() method with the INSERT constant, which represents the insertion cursor location. Syntax entry.index(INSERT) Where INSERT is a predefined constant that refers to the current cursor position in the Entry widget. Example Here's a complete example that demonstrates how to get the cursor position in a Tkinter Entry widget ? # Import required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter window ...

Read More

How to specify the file path in a tkinter filedialog?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 26-Mar-2026 6K+ Views

Tkinter offers several built-in functions and class library methods to build components and user-actionable items of an application. filedialog is one of the tkinter modules that provides classes and library functions to create file/directory selection windows. You can use filedialog where you need to ask the user to browse a file or a directory from the system. You can also specify the location of the directory from where a particular file should be picked up. To display the filedialog that starts from a particular location, use the initialdir = argument in the static factory function askopenfilename(initialdir=). This function ...

Read More

Python Tkinter – How to export data from Entry Fields to a CSV file?

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

The Entry widget in Tkinter allows users to input single-line text. You can export data from multiple Entry fields to a CSV file using Python's built-in csv module. This is useful for creating data entry forms that save user information to spreadsheet files. Creating the Data Entry Interface We'll create a simple form with name, age, and contact fields, along with buttons to add, save, and clear data ? # Import the required libraries import csv import tkinter as tk from tkinter import messagebox # Create main window window = tk.Tk() window.title("Data Entry") window.geometry("400x300") ...

Read More

How do I paste the copied text from the keyboard in Python?

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

Python's pyperclip module provides a simple way to access clipboard content and paste copied text in your applications. This cross-platform library works on Windows, macOS, and Linux systems. Installation First, install pyperclip using pip − pip install pyperclip Basic Clipboard Operations The pyperclip module provides two main functions for clipboard operations − import pyperclip # Copy text to clipboard pyperclip.copy("Hello, World!") # Paste text from clipboard clipboard_text = pyperclip.paste() print(clipboard_text) Hello, World! Creating a GUI Application with Tkinter Here's a practical example that ...

Read More

How to directly modify a specific item in a TKinter listbox?

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

Tkinter is a Python-based GUI application development library which is generally used to build useful functional desktop applications. The Listbox widget is another tkinter widget, which is used as a container to display a list of items in the form of a Listbox. To define a list of items in a Listbox widget, you'll need to create a constructor of Listbox(root, width, height, **options). You can insert as many items as you want to display in the listbox. To modify a specific item in a tkinter Listbox, you can first select the item from the list you want ...

Read More

How to explicitly resize frames in tkinter?

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

The Frame widget in tkinter serves as a container for organizing other widgets. You can explicitly control frame sizes using geometry managers like pack(), grid(), and place(), each offering different resizing capabilities. Using pack() with fill and expand The pack() geometry manager provides fill and expand options to control frame resizing ? import tkinter as tk # Create main window root = tk.Tk() root.geometry("600x400") root.title("Frame Resizing with pack()") # Create frames with different fill options top_frame = tk.Frame(root, bg="lightblue", relief="raised", bd=2) top_frame.pack(side="top", fill="x", padx=5, pady=5) bottom_frame = tk.Frame(root, bg="lightgreen", relief="raised", bd=2) bottom_frame.pack(side="bottom", fill="both", ...

Read More

Tkinter – How to create colored lines based on length?

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

Tkinter Canvas widget is one of the versatile widgets which is generally used to draw shapes, arcs, objects, display images or any content. The objects inside the Canvas widget can be modified as well as configured using the configure() method or within the constructor by providing values to the properties. To create lines on a Canvas widget, you can use the create_line(x1, y1, x2, y2, fill="color", width, **options) method. The coordinates x1, y1 define the starting point and x2, y2 define the ending point of the line. The distance between these points determines the length of the line. ...

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