Found 310 Articles for GUI-Programming

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

Dev Prakash Sharma
Updated on 25-May-2021 09:51:00

2K+ 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.Example#Import the Tkinter Library from tkinter import * #Create an instance of Tkinter Frame win ... Read More

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

Dev Prakash Sharma
Updated on 25-May-2021 09:50:31

7K+ Views

Tkinter Canvas Widget provides GUI features to an application. It can be used to draw shapes, animate objects, and configure the existing items in a canvas. Whenever we create shapes, we have to provide the size and coordinates of the shapes in the Canvas item constructor. In order to return the coordinates of an item on the Canvas, we can use the coords(item) method. It returns a list with the coordinates of the shapes in the canvas widget.Examplefrom tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry of Tkinter frame win.geometry("700x250") # Initialize a ... Read More

Return the input of the Entry widget in Tkinter

Dev Prakash Sharma
Updated on 13-Sep-2023 14:34:15

32K+ Views

An Entry widget in Tkinter is nothing but an input widget that accepts single-line user input in a text field. To return the data entered in an Entry widget, we have to use the get() method. It returns the data of the entry widget which further can be printed on the console.ExampleThe following example will return the input data that can be used to display in the window with the help of a Label Widget as well.#Import the required libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter Frame win = Tk() #Set the ... Read More

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

Dev Prakash Sharma
Updated on 25-May-2021 09:49:39

5K+ 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 itemconfig(**options) method. It takes options such as background color, outline color, and other useful properties of the items defined in a canvas.ExampleIn this example, we will create a rectangle such that the color inside the rectangle would change after clicking a Button.# Import the required libraries from tkinter import * from tkinter import ttk ... Read More

How to erase everything from a Tkinter text widget?

Dev Prakash Sharma
Updated on 25-May-2021 09:49:19

736 Views

Tkinter Text widget is more than just a multiline Entry widget. It supports the implementation of multicolored text, hyperlink text, and many more.Let us suppose a text widget has been created in an application. Now, to clear the Text widget, we can use the delete("1.0", END) method. It can be invoked in a callback function or event which can be triggered through an object of the Button Class.Example# Import the required libraries from tkinter import * # Create an instance of Tkinter Frame win = Tk() # Set the geometry win.geometry("750x250") # Define a function to clear ... Read More

How to create transparent widgets using Tkinter?

Dev Prakash Sharma
Updated on 25-May-2021 09:48:57

18K+ Views

A Tkinter widget in an application can be provided with 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.Example#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x250") #Adding transparent background property win.wm_attributes('-transparentcolor', '#ab23ff') #Create a Label Label(win, text= "This is a New line Text", font= ... Read More

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

Dev Prakash Sharma
Updated on 25-May-2021 09:21:28

11K+ Views

A checkbox widget is an input widget that has two values, either True or False. A checkbox is useful in many applications where a particular value needs to be validated.Let us suppose that we want to get the Input value from a checkbox such that if it is selected, then print the selected value. To print the value of the selected checkbox, we can use the get() method. It returns the input value of a particular widget.Example# Import Tkinter library from tkinter import * # Create an instance of tkinter frame win = Tk() # Set the geometry of ... Read More

Changing the Default Font for all the widgets in Tkinter

Dev Prakash Sharma
Updated on 25-May-2021 09:21:07

2K+ Views

Let us consider a case where we want to change the default font of a Tkinter application. To apply the font and setting it as the default font for a particular application, we have to use option_add(**options) method where we specify a property such as background color, font, etc. The changes made after defining the method will force all the widgets to inherit the same property.ExampleIn the given script, we have set a default font for the application such that it can be used for all the widgets defined in the application.#Import the required libraries from tkinter import * ... Read More

How to create a Popup Menu in Tkinter?

Dev Prakash Sharma
Updated on 25-May-2021 09:20:40

4K+ Views

We need menubars in applications where user interaction is required. Menus can be created by initializing the Menu(parent) object along with the menu items. A popup Menu can be created by initializing tk_popup(x_root, y_root, False) which ensures that the menu is visible on the screen. Now, we will add an event which can be triggered through the Mouse Button (Right Click). The grab_release() method sets the mouse button release to unset the popup menu.Example#Import the required libraries from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame win = Tk() #Set the geometry of the Tkinter library ... Read More

Configure tkinter/ttk widgets with transparent backgrounds

Dev Prakash Sharma
Updated on 25-May-2021 09:20:18

3K+ Views

Tkinter has many feature attributes and properties to frame the structure of an application and configure the widget. In this article, we will see how to set Tkinter widgets with a transparent background. The wm_attributes('-transparentcolor', 'color') method is used for providing the transparent background to the widget.ExampleIn this example, we will create a Label widget with transparent background.#Import the required libraries from tkinter import * #Create an instance of Tkinter Frame win = Tk() #Set the geometry win.geometry("700x350") #Adding transparent background property win.wm_attributes('-transparentcolor', '#ab23ff') #Create a Label Label(win, text= "Hello World!", font= ('Helvetica 18'), bg= '#ab23ff').pack(ipadx= 50, ... Read More

Advertisements