Articles on Trending Technologies

Technical articles with clear explanations and examples

How to add a column to a Tkinter TreeView widget?

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

Tkinter TreeView widget is used to present data in a hierarchical manner in the form of rows and columns. To create a Treeview widget, you have to first create a constructor of Treeview(master, column, show='headings') widget. Here, you can specify the list of columns and pass the value to the column parameter that you want to include in the table. The indexing of data in the Treeview widget starts from 0. Therefore, to avoid counting the first column, we need to use the show=heading parameter. Let us create an application to show a table with two columns "ID" and ...

Read More

How to temporarily remove a Tkinter widget without using just .place?

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

In Tkinter applications, you may need to temporarily remove widgets from the display without destroying them. While place() geometry manager uses place_forget(), other geometry managers have their own forget methods: pack_forget() and grid_forget(). Using place_forget() with place() The place() geometry manager positions widgets using absolute or relative coordinates. Use place_forget() to temporarily hide widgets placed with place() ? from tkinter import * # Create an instance of window win = Tk() win.geometry("700x300") def forget_label(): label.place_forget() def show_label(): label.place(relx=0.5, rely=0.2, anchor=CENTER) # Create a label ...

Read More

How to center a label in a frame of fixed size in Tkinter?

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

Tkinter is Python's standard GUI toolkit for building desktop applications. The Frame widget acts as a container to organize other widgets, and you can customize its size, background, and layout using geometry managers. To center a label inside a fixed-size frame, you can use the place() geometry manager with relx=0.5, rely=0.5, and anchor=CENTER properties. Basic Centering Example Here's how to center a label within a frame using the place() geometry manager ? import tkinter as tk # Create main window root = tk.Tk() root.geometry("700x350") root.title("Centered Label in Frame") # Create a fixed-size frame ...

Read More

Ask a user to select a folder to read the files in Python

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

The filedialog module in Tkinter provides built-in functions for displaying file and folder selection dialogs. While filedialog.askopenfilename() opens individual files, you can use filedialog.askdirectory() to let users select entire folders and read multiple files. Selecting a Single File The basic approach uses askopenfilename() to browse and select a file − import tkinter as tk from tkinter import filedialog # Create window root = tk.Tk() root.withdraw() # Hide the main window # Open file dialog filepath = filedialog.askopenfilename( title="Select a text file", filetypes=[("Text files", "*.txt"), ("All ...

Read More

How to get a string from a tkinter filedialog in Python 3?

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

To interact with the filesystem in a tkinter application, you can use the tkinter.filedialog module. It provides various built-in functions to create file selection dialogs, with askopenfilename() being the most commonly used to get a file path as a string. Basic File Selection Dialog The simplest way to get a file path string is using askopenfilename() − from tkinter import * from tkinter import filedialog # Create an instance of tkinter window win = Tk() win.geometry("700x300") # Create a dialog to select a file file_path = filedialog.askopenfilename( initialdir="/", ...

Read More

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 313 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
Showing 2531–2540 of 61,297 articles
« Prev 1 252 253 254 255 256 6130 Next »
Advertisements