Python Articles

Page 722 of 852

How do you check if a widget has a focus in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 4K+ Views

Let us assume that we want to check if a particular widget has a focused set or not. The only way to check the widget focus is to use the utility method focus_get(). It returns the object containing the widget’s information which is currently focused on, during the program’s execution. We will use the focus_get() method to find the active widget during our program’s execution.ExampleIn this example, we have created an Entry widget that will get its focus when we press the key. The focus_get() method will return the current widget’s information which is active.#Import the Tkinter library from ...

Read More

How do I get an event callback when a Tkinter Entry widget is modified?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 8K+ Views

Callback functions in Tkinter are generally used to handle a specific event happening in a widget. We can add an event callback function to the Entry widget whenever it gets modified. We will create an event callback function by specifying the variable that stores the user input. By using the trace("mode", lambda variable, variable: callback()) method with the variable, we can trace the input on the Label widget in the window.Example#Import the Tkinter library from tkinter import * #Create an instance of Tkinter frame win= Tk() #Define the geometry win.geometry("750x250") def callback(var):    content= var.get()    Label(win, text=content).pack() #Create an ...

Read More

How to change the font on ttk.Entry in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 3K+ Views

There are times when a user wants to insert the information like Name, contact number, Email, address, etc. Tkinter has a simple way to handle these types of inputs through its Entry widgets. Tkinter Entry widgets can be styled using the ttk package.To change other properties of the Entry widgets such as font properties, text-size, and font-style, we can use the font(‘font-family font-size font-style’) attribute. We can specify the font property in the entry constructor.Example#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 ...

Read More

How can I resize the root window in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 4K+ Views

In this example, we will see how to resize a tkinter window using the geometry manager. Tkinter geometry manager is generally used to configure the width and height of a tkinter window.The geometry(width, height)method takes width and height as instances and resizes the window accordingly. We can also define the position of the tkinter window by adding geometry(width x height, X, Y) where x and y are horizontal and vertical positions of the window.Example#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 ...

Read More

Get the text of a button widget in Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 13K+ Views

Let us suppose that for a particular application, we want to retrieve the button value by its name. In such cases, we can use the .cget() function. Every tkinter widget supports the .cget() function, as it can be used to retrieve the widget configuration such as value or name.ExampleIn this particular example, we will create a button and then store the button text in a variable "mytext". Using the variable, we will display the text in a Label widget.#Import tkinter library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame or window win= Tk() #Set ...

Read More

Get Application Version using Python

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 2K+ Views

In software industries, whenever developers add a new feature, fix bugs in a particular application, they name the application to a new version, as it helps to recognize the recently updated features in that application.Using Python, we can get the version of any application. We will use pywin32 to interact with the executable files. It provides access to the win32 API which gives the ability to create COM and objects.First, install the required package by typing pip install pywin32 in the command shell.Import Dispatch to get the version number of the application.Create a variable to store the location of the ...

Read More

Disable Exit (or [ X ]) in Tkinter Window

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 9K+ Views

The window manager implements the Tkinter window control icons. To hide and show the Tkinter window control icons, we can use the built-in function, which describes whether we want to disable control icons’ functionality.To disable the Exit or [X] control icon, we have to define the protocol() method. We can limit the control icon definition by specifying an empty function for disabling the state of the control icon.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") def close_win():    win.destroy() def disable_event(): ...

Read More

Convert Images to PDFs using Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 21-Apr-2021 660 Views

Python is a scripting language and thus, it helps in many ways to create file converters such as CSV to PDF, PDF to DOC, and vice-versa. With the help of certain libraries, we can also create an application that converts images into PDF. To create such an application, we use the img2pdf module in Python. It helps to parse the image binary and converts it into PDFs.We will follow these steps to create an application, First, make sure the system has img2pdf requirements already in place. Type pip install img2pdf on your terminal to install the package. Import img2pdf in ...

Read More

Permutation of a given string using the inbuilt function in Python

Hafeezul Kareem
Hafeezul Kareem
Updated on 16-Apr-2021 3K+ Views

In this tutorial, we are going to find the permutation of a string using the inbuilt function of Python called permutations. The method permutations is present in the itertools module.Procedure To Find The Permutation Of A StringImport the itertools module.Initialize the string.Use the itertools.permutations method to find the permutation of the string.In the third step, the method returns an object and convert it into a list.List contains a permutation of string as tuples.ExampleLet's see the program.## importing the module import itertools ## initializing a string string = "XYZ" ## itertools.permutations method permutaion_list = list(itertools.permutations(string)) ## printing the obj in list print("-----------Permutations Of String ...

Read More

Python Program to Sort using a Binary Search Tree

AmitDiwan
AmitDiwan
Updated on 16-Apr-2021 840 Views

When it is required to sort a binary search tree, a class is created, and methods are defined inside it that perform operations like inserting an element, and performing inorder traversal.Below is a demonstration of the same −Exampleclass BinSearchTreeNode:    def __init__(self, key):       self.key = key       self.left = None       self.right = None       self.parent = None    def insert_elem(self, node):       if self.key > node.key:          if self.left is None:             self.left = node             node.parent = self          else:             self.left.insert_elem(node)       elif self.key

Read More
Showing 7211–7220 of 8,519 articles
« Prev 1 720 721 722 723 724 852 Next »
Advertisements