Found 310 Articles for GUI-Programming

How to remove text from a label in Python?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:36:08

2K+ Views

Tkinter is a Python library that is used for creating and developing GUI-based applications. In this article, we will see how to remove text from a Label that will have some text in it.To remove text from a label, we will create an associated button that will act as a trigger for the Label.Example#import Tkinter Library from tkinter import * #Create an instance of tkinter frame win= Tk() #Define the size and geometry of the frame win.geometry("700x400") #Create a function for the Button Comman def remove_text():    text.config(text=" ") #Create a text Label text= Label(win, ... Read More

How to remove multiple selected items in the listbox in Tkinter?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:34:07

453 Views

Let us consider that we have created a listbox using the Listbox method in Tkinter and we want to remove multiple selected items from this list.In order to select the multiple list from the Listbox, we will use selectmode as MULTIPLE. Now iterating over the list, we can perform the delete operation using some buttons.Example#Import the required libraries from tkinter import * #Create an instance of tkinter frame or window win= Tk() #Set the geometry win.geometry("700x400") #Create a text Label label= Label(win, text="Select items from the list", font= ('Poppins bold', 18)) label.pack(pady= 20) #Define the function ... Read More

How to remove empty tags using BeautifulSoup in Python?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:31:46

652 Views

BeautifulSoup is a python library that pulls out the data from HTML and XML files. Using BeautifulSoup, we can also remove the empty tags present in HTML or XML documents and further convert the given data into human readable files.First, we will install BeautifulSoup library in our local environment using the command: pip install beautifulsoup4Example#Import the BeautifulSoup library from bs4 import BeautifulSoup #Get the html document html_object = """ Python is an interpreted, high-level and general-purpose programming language. Python's design philosophy emphasizes code readability with its notable use of significant indentation. """ #Let us create the soup ... Read More

How to open External Programs using Tkinter?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:28:02

388 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# Import the required Libraries from tkinter import * from tkinter import filedialog import os #Create ... Read More

How to make the Tkinter text widget read only?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:23:27

7K+ Views

In Tkinter, sometimes, we may want to make a text widget disabled. To achieve this, we can set the text configuration as DISABLED. This will freeze the text widget and will make it read-only.In this example, we will create a text widget and a button which will allow users to disable or freeze the text widget instantly.Example#Import the library from tkinter import * #Create an instance of window win= Tk() #Set the geometry of the window win.geometry("700x400") def disable_button():    text.config(state= DISABLED) #Label Label(win, text="Type Something", font=('Helvetica bold', 25), fg="green").pack(pady=20) #Create a Text widget text= ... Read More

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

Dev Prakash Sharma
Updated on 06-Mar-2021 08:21:22

7K+ Views

Tkinter is widely used to create GUI based applications. It has many toolkits and functions or modules available which can be used to define the different attributes of a particular application. For building GUI applications it provides some widgets including buttons, text boxes and labels. We can customize the position of the widget and its coordinates on the tkinter frame using other functions and libraries.Let us suppose that we have created a text label widget which is having some position in the tkinter frame. Now, to get the actual coordinates of the widget, we can use the geometry methods available ... Read More

How to Print Hard Copy using Tkinter?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:15:50

663 Views

Tkinter allows developers to interact with the files inside 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.In order to import these packages, we have to first install these modules in our environment. To install win32api, we will use pip install pywin32Example#import the required libraries from tkinter import * from tkinter import filedialog import win32api #Create an instance of tkinter frame or window win= Tk() win.title('Print Hard Copy') win.geometry("700x400") #Define function def print_file():    file= filedialog.askopenfilename(initialdir="/", title="Select any file", filetypes=(("Text ... Read More

How to Extract Wikipedia Data in Python?

Dev Prakash Sharma
Updated on 04-Mar-2021 14:09:24

1K+ Views

In this article, we will see how to extract Wikipedia data using Python. Python is widely used for creating web scrapers to capture the meta information from the websites.For this article, we will use the Wikipedia API and library to get the data from the Wikipedia source URL. The API will help to fetch the data from the given URL. Then, we will invoke the method on the given URL and print the information on the screen.In order to extract data from Wikipedia, we have to first import the wikipedia library in Python using 'pip install wikipedia'.In this program, we ... Read More

How To Dynamically Resize Button Text in Tkinter?

Dev Prakash Sharma
Updated on 04-Mar-2021 14:08:19

749 Views

Let us suppose we have created a button and a label in Tkinter Frame. The task is to allow the button text to dynamically resize to its main window. We can create the button using a button widget. However, there are several other functions used to create the button label dynamically.In this example, we will create two buttons with some labels in it. By using the Grid method such as rowconfigure() and columnconfigure(), we will dynamically resize the main window or the root.To make the button text dynamic, we will use the bind(, command) method which will help us to ... Read More

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

Dev Prakash Sharma
Updated on 04-Mar-2021 14:06:52

2K+ Views

Let us suppose that in a particular application, we have some fixed set of options or choices for the user in a drop-down list. The Options or Choices can be created using the OptionMenu Widget Constructor.OptionMenu(window, variable, choice1, choice2, choice3……)Once the option is created, it can be detected by a click event which generally prints whether a particular option is selected or not. For this example, we will simply create an application where a check button will be present with some choices from the range (1 to 9). By default, the button is set to “1” using the set method. ... Read More

Advertisements