GUI-Programming Articles

Page 22 of 25

Python program to calculate the number of digits and letters in a string

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 06-Mar-2021 11K+ Views

Let us suppose that we have a string and we have to calculate the total number of digits and letters present in the string.For ExampleInput −s = “tutorialsP0int”Output −Letters: 13 Digits: 1Explanation −Total number of letters and digits present in the given string are 13 and 1.Approach to Solve this ProblemTo calculate the total number of letters and digits in the given string, we have to first iterate over the whole string. If we get an alphabet, then we increment the letter count; otherwise, if we extract a digit, then increment the digit count.Take an input string.While iterating over the whole string, ...

Read More

On/Off Toggle Button Switch in Tkinter

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 06-Mar-2021 3K+ Views

Tkinter provides features for adding different kinds of widgets necessary for an application. Some of these widgets are: Button widget, Entry Widget, Text Box, Slider, etc. In this article, we will see how we can create an application with a button such that it can either be on or off.In this example, we will use these two buttons for demonstration, Switch OnSwitch OffExample# Import tkinter in the notebook from tkinter import * # Create an instance of window of frame win =Tk() # set Title win.title('On/Off Demonstration') # Set the Geometry win.geometry("600x400") win.resizable(0, 0) #Create a variable ...

Read More

How to use Unicode and Special Characters in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 06-Mar-2021 2K+ Views

Sometimes we need to add unicode and special charset in our Tkinter application. We can add unicode characters in our labels or widgets concatenating the signature as, u ‘/’. You can find the list of all unicode characters from hereIn this example, we will add a unicode character in the button widget.Example# Import the required Libraries from tkinter import * #Create an instance of tkinter frame win= Tk() win.geometry("700x200") #Create a button Button(win, text='Click'+u'\u01CF', font=('Poppins bold', 10)).pack(pady=20) #Keep running the window or frame win.mainloop()OutputRunning the above code will create a button with a unicode character (u01CF).

Read More

How to use Thread in Tkinter Python?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 06-Mar-2021 7K+ Views

With Tkinter, we can call multiple functions at a time using Threading. It provides asynchronous execution of some functions in an application.In order to use a thread in Python, we can import a module called threading and subclass its Thread class. Inside our new class, we need to overwrite the Run method and perform our logic in there.So, basically with threading, we can do multiple work at a time. To achieve threading in our application, Tkinter provides the Thread() function.Let us take an example and create a thread which will sleep for some time and then execute another function in ...

Read More

How to speed up scrolling responsiveness when displaying lots of text in Tkinter?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 06-Mar-2021 982 Views

Tkinter can also be used to render the text file and load it on the canvas. Further, the text files can be used for other purposes like manipulating the data, grabbing the data, and rendering the data for other uses.Let us suppose that we have to read a text in the tkinter canvas file which contains more than 10, 000 lines of queries in it. It would take a long time to search for a particular query in the canvas after loading the text file. To handle such large text files, we can speed up the responsiveness of the file ...

Read More

How to remove text from a label in Python?

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 06-Mar-2021 3K+ 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
Dev Prakash Sharma
Updated on 06-Mar-2021 879 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
Dev Prakash Sharma
Updated on 06-Mar-2021 934 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
Dev Prakash Sharma
Updated on 06-Mar-2021 662 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
Dev Prakash Sharma
Updated on 06-Mar-2021 8K+ 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
Showing 211–220 of 242 articles
Advertisements