Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Programming Articles
Page 24 of 2547
How to change the font on ttk.Entry in Tkinter?
There are times when a user wants to insert 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. Basic Example Here's how to create a ttk.Entry with custom font properties ? # Import tkinter library from tkinter import ...
Read MoreHow can I resize the root window in Tkinter?
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 x height) method takes width and height as parameters 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. Basic Window Resizing Here's how to create and resize a tkinter window ? # Import tkinter library from tkinter import ...
Read MoreGet the text of a button widget in Tkinter
When building Tkinter applications, you may need to retrieve the text content of a button widget dynamically. The cget() method allows you to get configuration values from any Tkinter widget, including button text. Syntax The basic syntax to get button text is − button_text = button.cget('text') Example Let's create a button and retrieve its text to display 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 the ...
Read MoreGet Application Version using Python
In software development, whenever developers add new features or fix bugs in an application, they assign it a new version number. This helps users identify the latest updates and features available in that application. Using Python, we can retrieve the version of any application installed on Windows systems. We'll use the pywin32 library to interact with executable files through the Win32 API, which provides access to Windows system information. Installation First, install the required package ? pip install pywin32 Getting Application Version Here's how to retrieve the version number of any Windows ...
Read MoreExtract hyperlinks from PDF in Python
To extract hyperlinks from PDF in Python can be done using several libraries like PyPDF2, PDFminer, and pdfx. Each offers different approaches and capabilities for extracting URLs from PDF documents. PyPDF2: A Python built-in library that acts as a PDF toolkit, allowing us to read and manipulate PDF files. PDFMiner: A tool used for extracting information from PDF documents, focusing on getting and analyzing text data. ...
Read MoreDisable Exit (or [ X ]) in Tkinter Window
The window manager implements the Tkinter window control icons. To hide and show the Tkinter window control icons, we can use the built-in protocol() 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. Syntax window.protocol("WM_DELETE_WINDOW", callback_function) Where: WM_DELETE_WINDOW - Protocol for window close event callback_function - Function to handle the close event (use empty function to ...
Read MoreCreating Tkinter full-screen application
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 attributes('-fullscreen', True) method. To make the window full-screen, just invoke the method with the particular window. Basic Full-Screen Example Here's how to create a basic full-screen Tkinter application ? # 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, ...
Read MoreConvert Images to PDFs using Tkinter
Python is a scripting language that helps create various file converters. Using the img2pdf module and Tkinter, we can build a GUI application that converts multiple images into PDF format. The img2pdf library efficiently parses image data and converts it to PDF without quality loss. Installation First, install the required module ? pip install img2pdf Building the Image to PDF Converter We will create a Tkinter application with file selection dialog and conversion functionality ? from tkinter import * from tkinter import filedialog, messagebox from tkinter import ttk import img2pdf import ...
Read MoreSort a List of Tuples in Increasing Order by the Last Element in Each Tuple using Python program
When working with lists of tuples, you often need to sort them based on the last element of each tuple. Python provides multiple approaches: using sorted() with a key function, the list.sort() method, or implementing a custom bubble sort algorithm. Using sorted() with Key Function The most Pythonic approach uses sorted() with a lambda function as the key ? data = [(1, 92), (34, 25), (67, 89)] print("Original tuple list:") print(data) # Sort by last element of each tuple sorted_data = sorted(data, key=lambda x: x[-1]) print("Sorted list of tuples:") print(sorted_data) Original tuple ...
Read MorePython Program to Find the Cumulative Sum of a List where the ith Element is the Sum of the First i+1 Elements From The Original List
When it is required to find the cumulative sum of a list where the ith element is the sum of the first i+1 elements from the original list, we can use different approaches. The cumulative sum creates a new list where each element represents the running total up to that position. Method 1: Using List Comprehension This approach uses list comprehension with slicing to calculate cumulative sums ? def cumulative_sum(my_list): cumulative_list = [] my_length = len(my_list) cumulative_list = [sum(my_list[0:x:1]) for x in range(1, my_length+1)] ...
Read More