Found 525 Articles for Tkinter

How to create an impressive GUI in Python using Tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 08:19:41
Tkinter is a standard Python GUI library in Python, which gives us an object-oriented interface with Tk GUI Toolkit. It's amazing how quickly one can create some really impressive looking apps. Actions in GUI are usually performed through direct manipulation of graphical elements.We will take a simple "addition" application to show how easy it is to create an impressive GUI in Python using tkinter. GUI is all about widgets and windows and these are available in Tkinter.First, we will import the Tkinter library, then create a window object (class Tk is used to create window object) and create a label ... Read More

Tkinter – How to create colored lines based on length?

Dev Prakash Sharma
Updated on 22-Dec-2021 08:06:11
Tkinter Canvas widget is one of the versatile widgets which is generally used to draw shapes, arcs, objects, display images or any content. The objects inside the Canvas widget can be modified as well as configured using the configure() method or within the constructor by providing values to the properties.To create lines on a Canvas widget, you can use the create_lines(x0, x1, x2, x3, fill="color", width, **options) constructor. In the constructor, you can assign the values of x0(top), x1(right), x2(bottom) and x3(left) which would decide the length of the lines to be drawn inside the canvas widget.ExampleLet's take an example ... Read More

Changing Tkinter Label Text Dynamically using Label.configure()

Dev Prakash Sharma
Updated on 22-Dec-2021 08:04:25
The Label widget in tkinter is generally used to display text as well as image. Text can be added in a Label widget by using the constructor Label(root, text= "this is my text"). Once the Label widget is defined, you can pack the Label widget using any geometry manager.If you want to configure the Label widget, you can use the configure() property. The configure() method allows you to edit the text as well other properties of the Label widget dynamically.ExampleLet us take an example to understand how we can dynamically change the tkinter label text using the configure() method. In ... Read More

How to stop Tkinter Message widget from resizing?

Dev Prakash Sharma
Updated on 22-Dec-2021 08:01:10
Tkinter Message widget is generally used to display text messages in a tkinter window. The Tkinter Message widget can also be configured by adding different properties to it, for example, font-properties, background and foreground color properties, and padding to widen the corners of the box, etc.Let us assume that we want to stop the Message widget from resizing, then we can use the fill=BOTH property in pack geometry manager while packing the Message widget. Let's take an example to demonstrate how it works.Example# Import the required library from tkinter import * # Create an instance of tkinter frame or ... Read More

How to stop copy, paste, and backspace in text widget in tkinter?

Dev Prakash Sharma
Updated on 16-Dec-2021 11:19:01
The Text widget accepts multiline user input, where you can type text and perform operations like copying, pasting, and deleting. There are certain ways to disable the shortcuts for various operations on a Text widget.In order to disable copy, paste and backspace in a Text widget, you’ve to bind the event with an event handler and return break using lambda keyword in python. The following example demonstrates how it works.Example# Import the required library from tkinter import * # Create an instance of tkinter frame or widget win=Tk() win.geometry("700x350") # Create a text widget text=Text(win, font="Calibri, 14") text.pack(fill= ... Read More

How to get the index of selected option in Tkinter Combobox?

Dev Prakash Sharma
Updated on 16-Dec-2021 11:15:20
If you want to create a dropdown list of items and enable the items of list to be selected by the user, then you can use the Combobox widget. The Combobox widget allows you to create a dropdown list in which the list of items can be selected instantly. However, if you want to get the index of selected items in the combobox widget, then you can use the get() method. The get() method returns an integer of the selected item known as the index of the item.ExampleLet’s take an example to see how it works. In this example, we ... Read More

How to get an Entry box within a Messagebox in Tkinter?

Dev Prakash Sharma
Updated on 16-Dec-2021 11:08:22
There are various methods and built-in functions available with the messagebox library in tkinter. Let's assume you want to display a messagebox and take some input from the user in an Entry widget. In this case, you can use the askstring library from simpledialog. The askstring library creates a window that takes two arguments, the title of the window, and the input title before the Entry widget. Let's take an example to understand how it works.Example# Import the required library from tkinter import * from tkinter.simpledialog import askstring from tkinter.messagebox import showinfo # Create an instance of tkinter frame ... Read More

Printing a list to a Tkinter Text widget

Gaurav Leekha
Updated on 13-Apr-2023 17:44:55
When creating a graphical user interface (GUI) in Python with Tkinter, it's common to want to display data in a user-friendly format. One way to do this is to print a list of items to a Tkinter Text widget, which allows you to display the list with each item on a separate line. In this article, we'll cover how to print a list to a Tkinter Text widget and some tips for formatting the output. Creating a Tkinter Text Widget Before we can print a list to a Tkinter Text widget, we need to create the widget itself. Here's some ... Read More

How to attach a vertical scrollbar to a Treeview using Tkinter?

Dev Prakash Sharma
Updated on 16-Dec-2021 11:05:44
If you want to display a list of items that contains some columns in it, then you can use the Treeview widget in Tkinter. The Treeview widget allows the user to add a large number of lists along with the properties that can be customized instantly.If you want to attach a vertical scrollbar to the list of items in a Treeview widget, then you can define a constructor of Scrollbar and configure it by adding the command to it. Let’s take an example and see how it works.Example# Import the required libraries from tkinter import * from tkinter import ttk ... Read More

How to disable multiselection on Treeview in tkinter?

Dev Prakash Sharma
Updated on 16-Dec-2021 11:04:14
The Treeview widget is used to display a list of items with more than one feature in the form of columns. By default, the listed items in a Treeview widget can be selected multiple times, however you can disable this feature by using selectmode="browse" in the Treeview widget constructor. The Treeview widget can be implemented by using the Treeview(root, column, **options) constructor.ExampleThe following example demonstrates how to disable multiselection in a Treeview widget.# Import the required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter frame win=Tk() # Set the size of ... Read More
Advertisements