Found 604 Articles for Tkinter

How to clear a Tkinter ListBox?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:19:37

11K+ Views

To create a list of items with a scrollable widget, Tkinter provides the Listbox widget. With the Listbox widget, we can create a list that contains items called List items. Depending upon the configuration, the user can select one or multiple items from the list.If we want to clear the items in the Listbox widget, we can use the delete(0, END) method. Besides deleting all the items in the Listbox, we can delete a single item as well by selecting an item from the Listbox, i.e., by using currselection() method to select an item and delete it using the delete() ... Read More

How to put a Toplevel window in front of the main window in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:17:55

3K+ Views

The Tkinter Toplevel window creates an additional window apart from the main window. We can add widgets and components to the newly created top-level window. It supports all the properties of the parent or main window.Sometimes the Toplevel window is also referred to as the child window. To put the child window in front of the parent window, we can use the wm_transient() method.Example# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame or window win=Tk() # Set the size of the window win.geometry("700x350") win.title("Parent Window") # ... Read More

How can I set the row height in Tkinter TreeView?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:16:58

7K+ Views

The treeview widget in Tkinter provides a way to represent the data in a hierarchical structure. With the Treeview widget, we can insert our data in the form of a table. The table can have rows and columns in which we can insert the data instantly.We can also configure the properties of the treeview widget such as its color, size, column width, height, row width & height, etc. To set the row height of the Treeview widget, you can create an instance of ttk themed widget where you can specify the rowheight property. The rowheight property will add internal padding ... Read More

How to attach a vertical scrollbar in Tkinter text widget?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:15:30

11K+ Views

The Scrollbar widget in tkinter is one of the useful widgets that is used to pack the container elements and their contents with a scrollbar. With Scrollbars, we can view large sets of data very efficiently.Generally, Tkinter allows to add vertical and horizontal scrollbar in the application. By default, the vertical scrollbars are available in the constructor and we don't need to have an orientation for the scrollbar. To attach a vertical scrollbar in a Tkinter text widget, you can use xscrollcommand and yscrollcommmand to set the value of vertical and horizontal scrollbars.Example# Import the required library from tkinter import ... Read More

How to get a horizontal scrollbar in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:14:14

6K+ Views

The Scrollbar widget in tkinter is one of the useful widgets that is used to pack the container elements and their contents with a scrollbar. With Scrollbars, we can view large sets of data very efficiently.Generally, Tkinter allows to add vertical and horizontal scrollbars. To add a horizontal scrollbar in an application, we've to use the orientation as Horizontal in the scrollbar constructor.ExampleLet us create a text editor that contains a horizontal scrollbar in it.# Import the required library from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of tkinter frame win=Tk() ... Read More

How do I use Window Manager (wm) attributes in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:13:10

4K+ Views

The Window Manager is a toolkit available in Tcl/Tk that can be accessed with the command 'wm'. The 'wm' command allows you to set the appearance and geometry of the Tkinter window. We can control the title, color, size, and other attributes with this command. The 'wm' command has numerous keywords that can be used to modify its property.Example# Import the required library from tkinter import * from tkinter import ttk from tkinter import messagebox # Create an instance of tkinter frame win=Tk() # Set the geometry win.geometry("700x350") Label(win, text="This window is disabled.",    font=("Calibri, 24")).pack() ... Read More

Passing arguments to a Tkinter button command

Dev Prakash Sharma
Updated on 05-Aug-2021 14:11:57

5K+ Views

The Button widget in Tkinter is generally used for pushing an event defined in an application. We can bind the events with buttons that allow them to execute and run whenever an action is triggered by the user.However, sharing the data and variables outside the function and events seems difficult sometimes. With the Button widget, we can pass arguments and data that allows the user to share and execute the event.In general, passing the arguments to a button widget allows the event to pick the arguments and use them further in the program.Example# Import the required library from tkinter import ... Read More

How to get a Popup Dialog in Tkinter/Python?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:10:23

3K+ Views

Tkinter is a standard Python library that is used to create and develop GUI-based applications. We can create an application in Tkinter and add widgets to it that make the application more interactive.Let's suppose we want to show a popup dialog in an application. In this case, we can use the built-in messagebox module in tkinter. It allows us to show the various dialog boxes such as errors, info box, confirmation boxes, etc.ExampleIn this example, we've created a button, which upon clicking will show a popup message on the screen.# Import the required library from tkinter import * from tkinter ... Read More

How do I use PIL with Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:06:51

3K+ Views

The PIL or Pillow package in Python provides a way to process images in a program. We can open an image, manipulate the image for different use, and can use it to visualize the data as well. In order to use the PIL package in Tkinter, you've to install the Python Pillow library in your environment.To install Pillow, just type pip install pillow. Once the installation has been successful, you can import the module in your project and use it for further implementation.ExampleIn this example, we've displayed an image in the canvas widget using Python Pillow package.# Import the required ... Read More

How to add a separator in Menu item in Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:04:36

2K+ Views

The Tkinter Menu widget is used to create a dropdown menu in an application. With menu widgets, we can select an item from the menu and run a specific task in the application.In many applications, we see a dotted separator line that separates the menu items in the menu. The separator separates the menu item of one type from another, and we can use it to visualize the hierarchy of the menu items. To create a separator among the menu items, you can use the add_separator() method.Example# Import the required libraries from tkinter import * from tkinter import ttk ... Read More

Advertisements