Found 604 Articles for Tkinter

Deleting a Label in Python Tkinter

Dev Prakash Sharma
Updated on 19-Jun-2021 08:47:30

19K+ Views

Tkinter label widgets are used to display text and images in the application. We can also configure the properties of Label widget that are created by default in a tkinter application.If we want to delete a label that is defined in a tkinter application, then we have to use the destroy() method.ExampleIn this example, we will create a Button that will allow the user to delete the label from the widget.# Import the required libraries from tkinter import * from tkinter import ttk from PIL import Image, ImageTk # Create an instance of tkinter frame or window win = ... Read More

How to hide and show canvas items on Tkinter?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:34:29

3K+ Views

The Canvas widget is one of the versatile widgets in Tkinter. It is used in many applications for designing the graphical user interface such as designing, adding images, creating graphics, etc. We can add widgets in the Canvas widget itself. The widgets that lie inside the canvas are sometimes called "Canvas Items".If we want to show or hide the canvas items through a Button, then this can be achieved by using the "state" property in itemconfig(id, state) method.ExampleIn this example, we will add an image in the canvas and a button will be used to show/hide the image in the ... Read More

How do I get the index of an item in Tkinter.Listbox?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:34:09

4K+ Views

We use the Tkinter Listbox widget to create a list of items. Each item in the listbox has some indexes that are assigned to them sequentially in vertical order.Let us suppose that we want to get the index of a clicked item in the listbox. Then, we have to first create a button that will capture the current selection of the items using list.curselection() method and then, we will print the index using the get() method.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() # Set the size ... Read More

How do I center the text in a Tkinter Text widget?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:33:48

17K+ Views

Tkinter text widget is a multiline text input widget. It is used to insert, delete, and add textual data in the input field. It provides many built-in functions and attributes in its widget class.To configure and align the text at the CENTER of a Tkinter Text widget, we can use justify=CENTER property.Example# 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") text=Text(win) # Configure the alignment of the text text.tag_configure("tag_name", justify='center') # Insert a Demo Text text.insert("1.0", "How do ... Read More

Difference between title() and wm_title() methods in Tkinter class

Dev Prakash Sharma
Updated on 19-Jun-2021 08:33:29

783 Views

Tkinter has a definite class hierarchy which contains many functions and built-in methods. As we create applications, we use these functions to build the structure of components.The wm class stands for "window manager" that is a mixin class that provides many builtin functions and methods.The method wm_title() is used to change the title of the tkinter window. However, alternatively, we can also use the win.title() method. Generally, wm class provides many methods that let us communicate with the window services.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win = Tk() ... Read More

How to edit a Listbox item in Tkinter?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:32:36

3K+ Views

Tkinter Listbox widget is generally used to create a list of items. It can store a list of numbers, characters and support many features like selecting and editing the list items.To edit the Listbox items, we have to first select the item in a loop using listbox.curselection() function and insert a new item after deleting the previous item in the listbox. To insert a new item in the listbox, you can use listbox.insert(**items) function.ExampleIn this example, we will create a list of items in the listbox widget and a button will be used for editing the selected item in the list.# ... Read More

How to make a system tray application in Tkinter?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:32:06

5K+ Views

A System Tray application is created for the continuous execution of the program. Whenever an application is closed by the user, it will get its state running on the taskbar. To identify a system tray application, we can provide an image or icon to its application.To create a System Tray icon of a tkinter application, we can use pystray module in Python. It has many inbuilt functions and methods that can be used to configure the system tray icon of the application.To install pystray in your machine, you can type "pip install pystray" command in your shell or command prompt.To ... Read More

How to add Label width in Tkinter?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:31:27

2K+ Views

A Label widget is used to display text and images in an application. The size of the label widget depends on a number of factors such as width, height, and Font-size of the Label text. The height and width define how the label widget should appear in the window.To set the width of the label widget, we should declare the Label widget with a variable. Instantiating the label widget with a variable allows the users to add/edit the properties of the Label widget.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or ... Read More

How to set the height/width of a Label widget in Tkinter?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:30:02

18K+ Views

The Label widgets are used for displaying text and images in the application. The size of the label widget depends on a number of factors such as width, height, and Font-size of the Label text.The height and width define how the label widget should appear in the window. To set the height and width of the label widget, we should declare the Label widget with a variable. Instantiating the label widget with a variable allows the users to add/edit the properties of the Label widget.Example# Import the required libraries from tkinter import * # Create an instance of tkinter ... Read More

How to stop a loop with a stop button in Tkinter?

Dev Prakash Sharma
Updated on 19-Jun-2021 08:29:35

6K+ Views

Consider a case of running a process in a loop and we want to stop the loop whenever a button is clicked. Generally, in programming languages, to stop a continuous while loop, we use a break statement. However, in Tkinter, in place of the while loop, we use after() to run the defined function in a loop. To break the continuous loop, use a global Boolean variable which can be updated to change the running state of the loop.For the given example, Create a global variable that works similar to the flag in a loop.Define two buttons, Start and Stop, to start and stop the execution.Define ... Read More

Advertisements