Found 10476 Articles for Python

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

Dev Prakash Sharma
Updated on 21-Apr-2021 07:45:47

3K+ 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
Updated on 21-Apr-2021 07:45:29

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
Updated on 21-Apr-2021 07:44:11

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
Updated on 21-Apr-2021 07:43:48

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
Updated on 21-Apr-2021 07:43:05

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
Updated on 21-Apr-2021 07:42:48

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

Extract hyperlinks from PDF in Python

SaiKrishna Tavva
Updated on 17-Sep-2024 10:42:53

4K+ Views

To extract hyperlinks from PDF in python can be done by using several libraries like PyPDF2, PDFminer and pdfx etc. PyPDF2 : A python bulit-in library acts as PDF toolkit, allows us to read and manipulate PDF files. PDFMiner : Tool used for extracting information from PDF documents, it focuses entirely on getting and analyzing text data. ... Read More

Disable Exit (or [ X ]) in Tkinter Window

Dev Prakash Sharma
Updated on 21-Apr-2021 07:41:25

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

Creating Tkinter full-screen application

Dev Prakash Sharma
Updated on 08-Oct-2021 13:01:26

3K+ Views

Tkinter initially creates a window that contains application components such as widgets and control bars. We can switch a native-looking application to a full-screen application by using the attribute(‘-fullscreen’, True) method. To make the window full-screen, just invoke the method with the particular window.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= Label(win, text=" HelloWelcome to Tutorialspoint.com!", font=('Century Schoolbook', 20, 'italic bold')) text.pack(pady=30) win.attributes('-fullscreen', True) win.mainloop()OutputExecuting the above code will ... Read More

Creating a prompt dialog box using Tkinter?

Dev Prakash Sharma
Updated on 21-Apr-2021 07:34:02

2K+ Views

Dialog Boxes are handy for informing users to perform certain operations. We are already familiar with the dialog boxes and interacted with them many times. In a particular Tkinter application, we can create any type of dialog boxes, such as Message, User Interaction Dialogs, Single Value Entry Dialogs, File chooser, etc. To create dialog boxes, Tkinter has several built-in packages like a messagebox, simpledialog, filedialog, and colorchooser.ExampleIn this example, we will create a message box to inform the user to choose an option.#Import the tkinter library from tkinter import * from tkinter import messagebox #Create an instance of Tkinter frame ... Read More

Advertisements