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

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

2K+ 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

15K+ 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

4K+ 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

1K+ 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 increase the font size of a Text widget?

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

760 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 hide or disable the mouse pointer in Tkinter?

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

4K+ Views

There are several ways to disable and enable a particular widget in a Tkinter application. However, if we want to control the Tkinter window components such as mouse cursor, control icons, toolbars, then Tkinter provides several built-in functions which can be used to configure the Tkinter window objects.To hide or disable the mouse pointer for a particular Tkinter application, then we can configure the mouse property using config(mouse= "none") method. It can be invoked for the master or root window.Example#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of Tkinter frame or window win= Tk() ... Read More

How to have image and text in one button in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 07:14:00

6K+ Views

We can load the images in a Tkinter application using the PhotoImage(image location) function, which takes the image location as the parameter and displays the image on the window object. However, when we try to add an image to the button, it generally appears on the button while hiding the button text. Therefore, to make the button text and pictures relative to each other, we typically use the compound property. It takes one of four positional arguments – LEFT, RIGHT, TOP, and BOTTOM, each defining the image’s position on the button.ExampleIn this example, we have used this image to make ... Read More

How to create a child window and communicate with parents in Tkinter?

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

3K+ Views

Unlike other Python libraries, Tkinter has many features that are used to create a full-fledged application. It supports multiple window operations and threading for processing the operation on Windows.Following the thread, we will create an application that will pull the data from root window and put it into a child window. The concept of child window can be referred to as Dialog Boxes which present some information to the user during the happening of an event. The child window in Tkinter is created very easily by using Toplevel(root) constructor.ExampleIn this example, we will create an entry widget along with a ... Read More

How to create a borderless fullscreen application using Python-3 Tkinter?

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

3K+ Views

In order to make a Tkinter window borderless and full-screen, we can use the utility method attributes(‘-fullscreen’, True). Tkinter windows can be configured using functions and methods defined in the Tkinter library.Another similar method Tkinter provides to make the application window full-screen is, overrideredirect(True). This method can be invoked only if the application needs to resize in its defined width and height only.Example#Import the required Libraries from tkinter import * #Create an instance of Tkinter frame win= Tk() #Set the Geometry win.geometry("750x250") #Full Screen Window win.attributes('-fullscreen', True) def quit_win():    win.destroy() #Create a Quit Button button=Button(win, text="Quit", font=('Comic Sans', 13, ... Read More

How can I create a dropdown menu from a List in Tkinter?

Dev Prakash Sharma
Updated on 22-Apr-2021 06:09:57

15K+ Views

Let us suppose we want to create a dropdown menu of a list in an application using tkinter. In this case, we can use the Tkinter OptionMenu(win, menu_to_set, options) function.First, we will instantiate an object of StringVar(), then we will set the initial value of the dropdown menu. We will create the dropdown menu by creating an object of OptionMenu and passing the value of window, menu object, and options which are to be displayed.Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the size of window or frame win.geometry("715x250") ... Read More

Advertisements