Dev Prakash Sharma

Dev Prakash Sharma

414 Articles Published

Articles by Dev Prakash Sharma

Page 23 of 42

How to change the color of certain words in a Tkinter text widget?

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

Tkinter text widgets allow you to create multiline text displays with rich formatting. You can change the color of specific words using the tag_add() and tag_config() methods. The tag_add(tag_name, start, end) method selects a range of text to format, while tag_config(tag_name, properties) applies styling like color, font, and background. Basic Example Here's how to change the color of specific words in a text widget ? import tkinter as tk # Create main window root = tk.Tk() root.geometry("600x250") root.title("Colored Text Widget") # Create text widget text_widget = tk.Text(root) text_widget.insert(tk.INSERT, "Hello World!") text_widget.insert(tk.END, "This is ...

Read More

How to clear an entire Treeview with Tkinter?

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

Tkinter Treeview widgets are used to display hierarchical data in a tree-like structure, similar to file explorers in Windows or Mac OS. When working with dynamic content, you often need to clear all items from a Treeview widget. To clear an entire Treeview, you can use the delete() method while iterating through all child items using get_children(). Syntax for item in treeview.get_children(): treeview.delete(item) Example − Creating and Clearing a Treeview In this example, we will create a treeview with programming languages categorized by Frontend and Backend, then demonstrate how ...

Read More

How to clear out a frame in the Tkinter?

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

Tkinter frames are used to group and organize widgets in an aesthetic way. A frame component can contain Button widgets, Entry widgets, Labels, ScrollBars, and other widgets. If we want to clear the frame content or delete all the widgets inside the frame, we can use the destroy() method. This method can be invoked by targeting the children of the frame using winfo_children(). Syntax for widget in frame.winfo_children(): widget.destroy() Example Here's a complete example showing how to clear all widgets from a frame ? # Import the ...

Read More

How to clear the contents of a Tkinter Text widget?

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

The Tkinter Text widget is used to create multi-line text areas in GUI applications. When you need to clear all content from a Text widget, you can use the delete() method with appropriate start and end positions. Syntax To clear the entire contents of a Text widget ? text_widget.delete("1.0", "end") Where: "1.0" - Start position (line 1, character 0) "end" - End of the text content Example Here's a complete example showing how to create a Text widget with a clear button ? # Import the tkinter library ...

Read More

How to clear the Entry widget after a button is pressed in Tkinter?

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

Tkinter Entry widgets are used to display a single line text that is generally taken in the form of user input. We can clear the content of Entry widget by defining a method delete(0, END) which aims to clear all the content in the range. The method can be invoked by defining a function which can be used by creating a Button object. Syntax The basic syntax to clear an Entry widget ? entry_widget.delete(0, END) Example In this example, we have created an entry widget and a button that can be used to ...

Read More

How to clear Tkinter Canvas?

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

Tkinter provides a way to add a canvas in a window, and when we create a canvas, it wraps up some storage inside the memory. While creating a canvas in Tkinter, it will effectively eat some memory which needs to be cleared or deleted. In order to clear a canvas, we can use the delete() method. By specifying "all", we can delete and clear all the canvas objects that are present in a Tkinter frame. Syntax canvas.delete("all") Where canvas is your canvas object and "all" removes all items from the canvas. Example ...

Read More

How to create a download progress bar in Tkinter?

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

When creating applications that download files or perform time-consuming tasks, a progress bar provides visual feedback to users. Tkinter's ttk.Progressbar widget is perfect for this purpose, allowing you to track and display progress in real-time. Basic Download Progress Bar Let's create a simple progress bar that simulates a download process ? import tkinter as tk from tkinter import ttk import time # Create main window root = tk.Tk() root.title("Download Progress") root.geometry("400x200") def start_download(): # Reset progress bar progress_bar['value'] = 0 ...

Read More

How to create a multiline entry with Tkinter?

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

When creating GUI applications in Tkinter, you might need an input field that accepts multiple lines of text. Unlike the standard Entry widget which only handles single lines, Tkinter provides the Text widget for multiline input. Basic Multiline Entry The Text() constructor creates a widget that supports multiline user input ? from tkinter import * # Create the main window win = Tk() win.title("Multiline Entry Example") win.geometry("650x250") # Create a Text widget for multiline input text = Text(win, height=10, width=50) text.pack(padx=10, pady=10) win.mainloop() This creates a basic multiline text entry field ...

Read More

How to create a password entry field using Tkinter?

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

When creating user interfaces with Tkinter, you often need a secure password entry field that hides the user's input. Tkinter's Entry widget provides a simple solution using the show parameter to mask password characters. Creating a Basic Password Field The key to creating a password field is using the show parameter in the Entry widget. This parameter specifies which character to display instead of the actual input ? from tkinter import * # Create an instance of tkinter frame win = Tk() # Set the geometry of frame win.geometry("600x250") win.title("Password Entry Example") def ...

Read More

How to delete Tkinter widgets from a window?

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

Sometimes, we want to remove a widget that is of no use in the application. We can delete widgets from the window or frame using the destroy() method in tkinter. It can be invoked on any widget by defining a function for it. Example In this example, we have created a button that will remove the text label widget from the window ? # Import the tkinter library from tkinter import * # Create an instance of tkinter frame win = Tk() # Set the geometry win.geometry("650x450") # Define a function to remove ...

Read More
Showing 221–230 of 414 articles
« Prev 1 21 22 23 24 25 42 Next »
Advertisements