Articles on Trending Technologies

Technical articles with clear explanations and examples

How to force Tkinter text widget to stay on one line?

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

Tkinter text widget can be configured by using the configure(**options) function. We can use it to configure the background color, foreground color, wrapping and other properties of the text widget. The wrap property of the Text widget controls how text wraps when it reaches the edge of the widget. By default, text wraps to the next line, but we can prevent this behavior to keep text on a single line. Understanding Text Wrapping Options The Text widget supports three wrap modes ? wrap=WORD − Wraps text at word boundaries (default) wrap=CHAR − Wraps text at ...

Read More

How to fully change the color of a Tkinter Listbox?

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

Tkinter Listbox widgets are very useful for displaying a large set of data items in list format. To change the appearance of the entire Listbox, including background and text colors, we can use the configure(**options) method to modify the widget's properties. Basic Color Configuration The most common approach is using the configure() method to set background, foreground, and other visual properties − # Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size of the window win.geometry("700x350") # Add ...

Read More

How to update information in the grid in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 766 Views

When working with Tkinter applications that use the Grid Geometry Manager, you often need to update widget properties dynamically. This can be accomplished using the configure(**options) method. The key is to assign your widgets to variables during creation, giving you global access to modify their properties later. Basic Widget Configuration Here's how to create a widget and update its properties − import tkinter as tk # Create the main window root = tk.Tk() root.geometry("700x350") root.title("Grid Information Update Example") # Create a label widget and assign to variable label = tk.Label(root, text="This is Houston Control. ...

Read More

Moving balls in Tkinter Canvas

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

Tkinter is a standard Python library used to create GUI-based applications. To create a simple moving ball application, we can use the Canvas widget which allows users to add images, draw shapes, and animate objects. Key Components The application consists of the following components − A Canvas widget to draw the oval or ball in the window A move_ball() function that updates the ball's position and handles collision detection with canvas walls The canvas.after() method to schedule regular position updates Speed variables to control ...

Read More

How to capture events on Tkinter child widgets?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 763 Views

When building interactive Tkinter applications, you often need to capture events on child widgets like buttons, listboxes, or entry fields. This involves creating callback functions that respond to user interactions such as clicks, selections, or key presses. Understanding Event Handling Event handling in Tkinter works through callback functions − functions that execute when specific events occur. You connect these functions to widgets using parameters like command for buttons or by binding events directly. Example: Capturing Listbox Selection Events Let's create a Listbox widget that captures selection events. When a user selects an item and clicks a ...

Read More

How to create a Tkinter toggle button?

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

Python's Tkinter library provides a comprehensive set of widgets for creating GUI applications. A toggle button is a special type of button that switches between two states when clicked, commonly used for on/off functionality like enabling night mode or day mode in applications. To create a toggle button in Tkinter, we use a regular Button widget with custom images and a function that changes the button's state and appearance when clicked. The key is using a global variable to track the current state. Creating a Basic Toggle Button Here's how to create a toggle button that switches ...

Read More

What is the difference between focus and focus_set methods in Tkinter?

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

In Tkinter, focus refers to which widget is currently accepting keyboard input. The focus() and focus_set() methods are used to programmatically set focus to a widget, making it active for user input. Key Difference Both focus() and focus_set() perform the same function – they are identical methods. The focus_set() method is simply an alias for focus(), provided for clarity and consistency with other Tkinter naming conventions. Syntax widget.focus() # OR widget.focus_set() Example Here's how to use both methods to set focus on an Entry widget ? import tkinter as tk ...

Read More

How can I change the text of the Tkinter Listbox item?

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

To display a list of items in the application, Tkinter provides a Listbox widget. It is used to create a list of items vertically. When we want to change the text of a specific Listbox item, we have to first select the item by iterating over the listbox.curselection() and insert a new item after deletion. To insert an item in the list, you can use listbox.insert(). Example Here's a complete example that demonstrates how to change the text of a selected Listbox item ? # Import the required libraries from tkinter import * from tkinter import ...

Read More

Delete and Edit items in Tkinter TreeView

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 18K+ Views

Tkinter Treeview widget is used to display data in a hierarchical structure where each row can represent a file or directory. The Treeview widget items can be edited and deleted by selecting them using tree.selection() function and then performing operations on the selected items. Creating a Treeview Widget To create a Treeview widget, we use the Treeview(parent, columns) constructor ? import tkinter as tk from tkinter import ttk # Create the main window root = tk.Tk() root.geometry("700x350") root.title("Treeview Edit and Delete Example") # Create a Treeview widget tree = ttk.Treeview(root, columns=("c1", "c2"), show='headings', height=8) ...

Read More

How to get coordinates on scrollable canvas in Tkinter?

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

The canvas widget in Tkinter has two coordinate systems: window coordinates and canvas coordinates. Window coordinates always start from (0, 0) at the top-left corner of the visible window, while canvas coordinates represent the actual position of items within the entire canvas area, including scrolled regions. When working with scrollable canvases, mouse events return window coordinates, but you often need canvas coordinates to place or interact with canvas items correctly. Converting Window to Canvas Coordinates Tkinter provides two methods to convert window coordinates to canvas coordinates: canvas.canvasx(event.x) # Convert x coordinate canvas.canvasy(event.y) # ...

Read More
Showing 4191–4200 of 61,297 articles
« Prev 1 418 419 420 421 422 6130 Next »
Advertisements