GUI-Programming Articles

Page 2 of 25

Python Tkinter – How to display a table editor in a text widget?

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

Tkinter is a Python-based GUI toolkit that is used to create full-fledged desktop applications. Tkinter has a variety of modules and class libraries to help developers create user-friendly applications quickly and easily. The Text widget in tkinter provides users a way to create a text editor that accepts multiline user-input. You can configure and customize its properties and attributes. To display tabular data using Text widgets, we create multiple Text widgets arranged in a grid pattern where each widget acts as a cell in the table. Approach To create a table-like structure using Text widgets, follow these ...

Read More

How to disable an Entry widget in Tkinter?

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

Tkinter Entry widget accepts single line user-input in an entry field. You can customize the width, background color and size of the entry widget based on the need of your application. To disable an Entry widget, you can use the state='disabled' property either in the constructor or by calling the config() method. Disabling the Entry widget prevents users from editing or adding values to it, and visually greys out the widget. Method 1: Disabling During Creation You can disable an Entry widget when creating it by setting state='disabled' in the constructor ? import tkinter as ...

Read More

How to resize an Entry Box by height in Tkinter?

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

An Entry widget in a Tkinter application supports single-line user inputs. You can configure the size of an Entry widget such as its width using the width property. However, Tkinter has no height property to set the height of an Entry widget. To set the height, you can use the font('font_name', font-size) property. The font size of the text in an Entry widget always works as a height of the Entry widget. Example Let us take an example to understand this more clearly. Follow the steps given below − Import the required libraries Create an Entry ...

Read More

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
Showing 11–20 of 242 articles
« Prev 1 2 3 4 5 25 Next »
Advertisements