Found 310 Articles for GUI-Programming

How to directly modify a specific item in a TKinter listbox?

Dev Prakash Sharma
Updated on 22-Dec-2021 08:13:47

787 Views

Tkinter is a Python-based GUI application development library which is generally used to build useful functional desktop applications. The Listbox widget is another tkinter widget, which is used as a container to display a list of items in the form of a Listbox.To define a list of items in a Listbox widget, you'll need to create a constructor of Listbox(root, width, height, **options). You can insert as many items as you want to display in the listbox.Suppose you want to modify a specific item in a tkinter Listbox, then you can first create a button to select the item from ... Read More

How to change the background color of a tkinter Canvas dynamically?

Dev Prakash Sharma
Updated on 22-Dec-2021 08:11:43

15K+ Views

The Canvas widget is one of the most useful widgets in Tkinter. It has various functionalities and features to help developers customize the application according to their need. The Canvas widget is used to display the graphics in an application. You can create different types of shapes and draw objects using the Canvas widget.To change the background color of the Canvas widget, you can use the configure() method. Here, you can specify the background color of the Canvas widget which you want to change explicitly.ExampleIn the following example, we have created a canvas widget with a default background color "skyblue", ... Read More

How to explicitly resize frames in tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 08:10:07

5K+ Views

The Frames widget in tkinter is generally used to display widgets in the form of a container. The Frame widget works similar to the default window container. The geometry and size of the frame widget can be configured using various geometry managers available in the tkinter library.Considering the case, if you want to configure the size of the frame explicitly, you can use the pack() geometry manager by specifying the side and padding property. The pack() geometry manager gives proper accessibility to the widget for resizing.ExampleIn the following example, we will create two frames and resize them using the pack() ... Read More

How to create an impressive GUI in Python using Tkinter?

Dev Prakash Sharma
Updated on 22-Dec-2021 08:19:41

791 Views

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

948 Views

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

6K+ Views

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

393 Views

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

451 Views

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

8K+ Views

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

5K+ Views

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

Advertisements