Python Articles

Page 534 of 855

How to remove empty tags using BeautifulSoup in Python?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 954 Views

BeautifulSoup is a Python library that pulls out data from HTML and XML files. Using BeautifulSoup, we can remove empty tags present in HTML or XML documents and convert the data into clean, human-readable format. First, install the BeautifulSoup library using: pip install beautifulsoup4 Basic Example − Removing Empty Tags Here's how to identify and remove empty tags from an HTML document ? from bs4 import BeautifulSoup # HTML document with empty tags html_document = """ Python is an interpreted, high-level programming language. ...

Read More

How to open External Programs using Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 680 Views

Sometimes, while creating an application, we need to interact with external programs and applications. In order to interact with the system's applications and programs, we have to use os Module in python. In this article, we will see how we can interact with external programs and open files using the OS module in Python. First, we will define a function that will open the chosen file using the filedialog library in Python. Then, we will print the path and open the file using the os module. Example Let's create a Tkinter application that allows users to ...

Read More

How to make the Tkinter text widget read only?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 8K+ Views

In Tkinter, you can make a text widget read-only by setting its state configuration to DISABLED. This prevents users from editing the content while keeping it visible and readable. Making Text Widget Read-Only Use the config() method to change the state of a text widget ? from tkinter import * # Create an instance of window win = Tk() win.geometry("700x400") win.title("Read-Only Text Widget") def disable_button(): text.config(state=DISABLED) def enable_button(): text.config(state=NORMAL) # Label Label(win, text="Type Something", font=('Helvetica bold', 25), ...

Read More

How to get the Tkinter widget's current x and y coordinates?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 10K+ Views

Tkinter is widely used to create GUI-based applications. It provides various widgets including buttons, text boxes, and labels. We can customize the position of widgets and retrieve their coordinates on the tkinter frame using geometry methods. To get the actual coordinates of a widget, we can use the geometry methods available in tkinter's library. The winfo_rootx() and winfo_rooty() functions return the actual coordinates of the widget with respect to the root window. Syntax widget.winfo_rootx() # Returns x-coordinate widget.winfo_rooty() # Returns y-coordinate Example Here's how to get the current coordinates of different ...

Read More

How to Print Hard Copy using Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 1K+ Views

Tkinter allows developers to interact with files in the local system. In this article, we will see how to print a hardcopy of a file using Tkinter packages such as filedialog and win32api module. To use the win32api module, you need to install it first using pip install pywin32. Required Imports We need three main imports for this functionality − import tkinter as tk from tkinter import filedialog import win32api Complete Example Here's a complete example that creates a GUI for selecting and printing files − # Import the required ...

Read More

How to Extract Wikipedia Data in Python?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 2K+ Views

Wikipedia is a vast source of information that can be programmatically accessed using Python. The wikipedia library provides a simple interface to extract content, summaries, and page details from Wikipedia articles. Installing the Wikipedia Library First, install the wikipedia library using pip ? pip install wikipedia Basic Wikipedia Data Extraction Here's how to search for a topic and extract its summary ? import wikipedia # Search for a topic results = wikipedia.search("Python Programming") print("Search results:", results[:3]) # Get the page page = wikipedia.page(results[0]) # Extract basic information print("Title:", ...

Read More

How To Dynamically Resize Button Text in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 1K+ Views

Tkinter buttons with static text can look unprofessional when the window is resized. This tutorial shows how to make button text dynamically resize based on the window dimensions using the event and font configuration. Understanding Dynamic Text Resizing Dynamic text resizing requires three key components ? Grid weight configuration − Makes buttons expand with the window Configure event binding − Detects window size changes Font scaling function − Adjusts text size based on dimensions Basic Dynamic Button Example Here's a complete example that resizes button text based on window width ? ...

Read More

How to detect when an OptionMenu or Checkbutton changes in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 3K+ Views

In Tkinter applications, you often need to detect when a user selects an option from a dropdown menu or clicks a checkbutton. This is useful for updating the interface or performing actions based on user choices. Detecting OptionMenu Changes The OptionMenu widget allows users to select from a dropdown list of options. You can detect changes using a callback function with the command parameter ? Syntax OptionMenu(parent, variable, *choices, command=callback_function) Example import tkinter as tk from tkinter import * # Create main window root = tk.Tk() root.geometry("400x200") root.title("OptionMenu Change Detection") ...

Read More

How to Delete Tkinter Text Box's Contents?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 8K+ Views

Tkinter provides many functions and modules through which we can create fully featured applications with buttons, dialogue boxes, widgets, and many more. To create a text widget, we can use the tkinter Text widget which is basically a constructor that takes the window or frame of the tkinter. We can delete the content of this text widget using the built-in method delete(first, last=None) which takes a range within the textbox. Syntax text_widget.delete(start, end) Parameters: start − Starting position (e.g., "1.0" for beginning) end − Ending position (e.g., "end" for end of text) ...

Read More

How to create a Splash Screen using Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 25-Mar-2026 3K+ Views

A splash screen is a temporary window that appears when an application starts, typically showing a logo, loading message, or application name. In Tkinter, you can create a professional splash screen that displays briefly before the main application window opens. Steps to Create a Splash Screen To create a splash screen using Tkinter, follow these steps: Create a splash window with labels and styling Make the splash screen borderless using overrideredirect() Create a function for the main window Use the after() method to control display timing Example Here's a complete example showing how ...

Read More
Showing 5331–5340 of 8,546 articles
« Prev 1 532 533 534 535 536 855 Next »
Advertisements