Python Articles

Page 113 of 855

How to delete all children's elements using Python's Tkinter?

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

Frames are very useful in a Tkinter application. If we define a Frame in an application, it means we have the privilege to add a group of widgets inside it. However, all these widgets are called children of that particular Frame. Let us suppose that we want to remove all the children widgets defined in a frame. Then, first we have to get the focus on children using the winfo_children() method. Once we get the focus, we can delete all the existing children using destroy() method. Syntax widget.winfo_children() # Returns list of child ...

Read More

How to get the coordinates of an object in a Tkinter canvas?

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

The Tkinter Canvas widget provides GUI features for drawing and managing graphical objects. When creating shapes, you specify their size and coordinates in the constructor. To retrieve the coordinates of any canvas item later, use the coords(item) method, which returns a list containing the object's coordinate values. Syntax canvas.coords(item_id) Parameters item_id − The ID of the canvas item (returned when creating the item) Return Value Returns a list of coordinates. For rectangles and ovals, this contains [x1, y1, x2, y2] representing the bounding box. Example Here's how to ...

Read More

How to change the color of a Tkinter rectangle on clicking?

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

The Canvas widget is one of the most versatile widgets in the Tkinter Library. It is used for creating shapes of different types and sizes, animating objects, visualizing graphics, and many more. To change the property of a particular item in Tkinter, we can use the itemconfig(**options) method. It takes options such as background color, outline color, and other useful properties of the items defined in a canvas. Example In this example, we will create a rectangle such that the color inside the rectangle would change after clicking a Button ? # Import the required libraries ...

Read More

How to create transparent widgets using Tkinter?

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

A Tkinter widget in an application can be provided with a transparent background. The background property of any widget is controlled by the widget itself. However, to provide a transparent background to a particular widget, we have to use wm_attributes('-transparentcolor', 'colorname') method. It works in the widget only after adding the same transparent color as the background color of the widget. How Transparent Widgets Work The transparency effect works by defining a specific color that becomes transparent. Any widget using this exact color as its background will appear transparent, allowing you to see through to whatever is ...

Read More

How to get the input from a Checkbox in Python Tkinter?

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

A checkbox widget in Python Tkinter is an input widget that represents a boolean state - either checked (True) or unchecked (False). Checkboxes are commonly used in GUI applications where users need to select one or more options from a list. To get the input value from a checkbox, we use the get() method on the variable associated with the checkbox. This method returns the current state of the checkbox. Basic Checkbox Example Here's how to create checkboxes and retrieve their values ? # Import Tkinter library from tkinter import * # Create an ...

Read More

Changing the Default Font for all the widgets in Tkinter

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

In Tkinter applications, you can set a default font that applies to all widgets using the option_add() method. This method allows you to specify global properties like font, background color, and other styling options that all widgets will inherit. Syntax window.option_add(pattern, value) Parameters: pattern − The property pattern (e.g., "*Font", "*Background") value − The value to set for that property Setting Default Font for All Widgets Here's how to apply a default font to all widgets in your Tkinter application − # Import the required libraries from tkinter import ...

Read More

Configure tkinter/ttk widgets with transparent backgrounds

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

Tkinter provides the ability to create widgets with transparent backgrounds using the wm_attributes() method. The wm_attributes('-transparentcolor', 'color') method makes all pixels of a specified color completely transparent in your window. How Transparent Background Works The wm_attributes('-transparentcolor', color) method tells the window manager to treat all pixels of the specified color as transparent. Any widget or background area using that exact color will become see-through, revealing whatever is behind the window. Example Here's how to create a Label widget with a transparent background − # Import the required libraries from tkinter import * # ...

Read More

How to remove the dashed line from the Tkinter menu UI?

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

A Menu Bar contains vertically stacked menu items. We can create a Menu bar by initializing the object of Menu(root). Whenever we initialize a Menu bar in an application, it displays a dashed line separator at the top of each dropdown menu by default. To remove the separator or the dashed line from the Menu, we can use the tearoff property. Setting tearoff=0 or tearoff="off" removes this dashed line and creates a cleaner menu appearance. Syntax menu_object = Menu(parent, tearoff=0) Example Without Tearoff (Clean Menu) Here's how to create a menu without the ...

Read More

How to get the width of the Tkinter widget?

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

Tkinter widgets are supposed to be present in the Tkinter application window. All the widgets can be configured and customized by using predefined properties or functions. To get the width of a widget in a Tkinter application, we can use the winfo_width() method. It returns the width of the widget in pixels which can be printed or used for calculations. Syntax widget.winfo_width() This method returns the current width of the widget as an integer value in pixels. Example Here's how to get the width of a Label widget ? # ...

Read More

Read an image with OpenCV and display it with Tkinter

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

OpenCV is an Open Source Computer Vision library in Python which is widely used for Research purposes in Artificial Intelligence and Machine Learning. Computer Vision Library such as OpenCV deals with image processing. We can use OpenCV to read an image and further use it for development. Let us suppose that we want to create an application that reads an image and displays it in the window using OpenCV with Tkinter as the GUI framework. Installation Install OpenCV by using the following command ? pip install opencv-python Also install Pillow for image processing ...

Read More
Showing 1121–1130 of 8,549 articles
« Prev 1 111 112 113 114 115 855 Next »
Advertisements