Found 604 Articles for Tkinter

How to select a directory and store the location using Tkinter in Python?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:41:07

5K+ Views

We are familiar with dialog boxes and interacted with them in many types of applications. Such types of dialogs are useful in creating an application where user interaction is a prime need. We can use the dialog boxes to ask the user to select different types of files and then perform certain operations such as reading the file, writing to the file, etc. The dialog boxes can be created by using the filedialog Module in Python.ExampleIn this example, we will create an application that will ask the user to select a file from the local directory and then will display ... Read More

How to reset the background color of a Python Tkinter button?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:27:58

2K+ Views

Tkinter buttons are useful for handling events within the application. We can configure the button properties such as text style, font-family, background color, text color, and text size using predefined properties.We can reset the background color and other properties by defining a callback function.Example#Import the tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win= Tk() #Define the geometry of the function win.geometry("750x250") #Define a function to change the properties of button def change_color():    btn.configure(bg="OrangeRed3", fg= "white") #Create a Label Label(win, text= "Click the Button to reset the Color of the Button", ... Read More

How to remove the outline of an oval in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:25:48

686 Views

With Tkinter canvas, we can draw shapes for 2D or 3D applications, we can create images, draw animation, and many more things. Let us suppose that we have to create an oval that should be drawn aesthetically on the canvas. There can be other features that can be present to give the oval and other shapes an aesthetic look. To remove the outlining from the shapes in the canvas, we can provide an empty value to the outline property in the method.Example#Import tkinter library from tkinter import * #Create an instance of tkinter frame or window win= Tk() #Set the ... Read More

How to pass an argument to the event handler in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:25:27

1K+ Views

In most situations, the callback functions can refer to as an Instance Method. An instance method accesses all its members and performs operations with them without specifying any arguments.Let's consider a case where more than one component is defined and we want to handle some events with those components. To run multiple events, we prefer to pass multiple arguments in event handlers.ExampleIn this example, we have created multiple button widgets in a frame, and we will handle various events by passing the name of the widget as arguments. Once a Button will be clicked, it will update the Label widget ... Read More

How to open a new window by the user pressing a button in a tkinter GUI?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:23:31

13K+ Views

Tkinter creates a default window (i.e., master or root window) for every application. In tkinter, we can create a Popup window or a child window by defining a Toplevel(master) constructor. This will allow the tkinter application to create another window which can be resized dynamically by defining its size property.ExampleIn this example, we have created a button widget that will open the new window with a text label.#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Define a new function to ... Read More

How to list available font families in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:21:57

3K+ Views

Tkinter font property is one of the most valuable properties used to customize a widget's default font. We have already seen so many fonts and used them in our widgets, but sometimes, it seems complicated to guess which font is applicable in the Tkinter library. Python Tkinter is more specific about choosing the font. We can create an application which can list all the available font in the Tkinter library.To use the font library, we have to import it in our environment using, from tkinter import fontThere are a few steps to create this particular application, Define a function and ... Read More

How to keep selections highlighted in a Tkinter Listbox?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:17:11

937 Views

Let us consider a situation for a particular system that we have to keep selecting multiple files from a directory and once copied in the clipboard paste all of them into another directory. The idea of making the multiple selections in ListBoxes can be done by using the exportselection property. It allows a Listbox to keep the selection alive while selecting an item from another ListBox. To configure a Listbox to behave like keep selection steady we can make exportselection =False.Example#Import tkinter library from tkinter import * #Create an instance of Tkinter frame or window win= Tk() #Set the geometry ... Read More

How to justify text in label in tkinter in Python Need justify in tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:16:52

8K+ Views

Tkinter Label widgets are used to add images and create text in a particular application. There are various functions and methods available in the library which can be used to style the widgets and its property. In order to justify the text in the label widget, we can use the justify property. It is generally used to justify the position or the alignment of the text such as RIGHT, LEFT, and CENTER.ExampleIn this application, we will justify the position of a text label using the justify property.#Import tkinter library from tkinter import * #Create an instance of tkinter frame or ... Read More

How to increase the font size of a Text widget?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:16:33

556 Views

We can customize the Tkinter widget by modifying the value of its properties such as font-family, text-size, text-size, width, the height of the frame, etc. Tkinter Text widgets are generally used for accepting multiline user input. It is similar to a standard text widget.To configure the text properties of the a widget, we can use the font(‘font-family font-size font-style) attribute by defining its font-family, font-size, and the font style.Example#Import tkinter library from tkinter import * #Create an instance of Tkinter frame or window win= Tk() #Set the geometry of tkinter frame win.geometry("750x250") #Create a Text widget text= Text(win, width= 60, ... Read More

How to horizontally center a widget using a grid() in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:16:12

8K+ Views

As the name suggests, a grid is nothing but a set of rows and columns. Tkinter grid manager works similarly; it places the widget in a 2-dimensional plane to align the device through its position vertically and horizontally.Let us consider an example where we want to make the widget centered in the window while resizing it. The grid(row, column) property will help to make the label widget centered horizontally, and the sticky property will avoid resizing the widget in the window.Example#Import tkinter library from tkinter import * #Create an instance of Tkinter frame or window win= Tk() #Set the geometry ... Read More

Advertisements