Found 310 Articles for GUI-Programming

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

Dev Prakash Sharma
Updated on 06-Mar-2021 08:57:30

9K+ 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
Updated on 06-Mar-2021 08:55:37

2K+ 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
Updated on 06-Mar-2021 08:51:51

851 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
Updated on 06-Mar-2021 08:48:20

5K+ 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 Use Images as Backgrounds in Tkinter?

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

6K+ Views

If we will create an instance of Tkinter frame and display the window while keep running it, then it will show the default output canvas. However, we can add an image inside the Tkinter canvas as a background using PhotoImage methods and Canvas methods.Since image support in Tkinter is limited to Gif, PNG and PPM, the PhotoImage(GIF, PNG, PPM) function takes the location of the image file and displays the canvas with the image as a background.First, we will create a PhotoImage Object using the PhotoImage function.Examplefrom tkinter import * from PIL import ImageTk win = Tk() win.geometry("700x300") ... Read More

How to use Bitmap images in Button in Tkinter?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:45:10

667 Views

In Tkinter, we can create and customize buttons using images. These images can be uploaded by using the Python PhotoImage(file) function.However, PhotoImage() supports only a few image types such as PNG, PPM, and GIF. In addition, we can create buttons using BitMap images too. A bitmap image is nothing but a set of dots aligned in a matrix which represents a pixel of the image. The following types of bitmap attributes are available in Tkinter, "error""gray75""gray50""gray25""gray12""hourglass""info""questhead""question""warning"Examplefrom tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("700x300") win.resizable(0, 0) Button(win, relief=RAISED, bitmap="info").pack(pady=10) Button(win, relief=RAISED, bitmap="gray50").pack(pady=10) ... Read More

How to use an Image as a button in Tkinter?

Dev Prakash Sharma
Updated on 15-Sep-2023 02:22:26

27K+ Views

In this example, we will create a rounded button in a window that can be used in many other applications like forms, games, dialogue boxes, etc.The best way to create rounded buttons in Tkinter is to use the desired images of buttons and turn it into a clickable button in the frame. That is really possible by using PhotoImage() function which grabs the desired image of the button.So, the following steps make the desired image a button, First, we will create a dummy button which can be used to make the image clickable.Grab the image from the source using PhotoImage(file) ... Read More

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

Dev Prakash Sharma
Updated on 06-Mar-2021 08:41:55

524 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 Set a Tkinter Window with a Constant Size?

Dev Prakash Sharma
Updated on 06-Mar-2021 08:40:00

3K+ Views

Sometimes, the tkinter frame gets resized automatically according to the size of the widgets. To make the frame constant in size, we have to stop the widgets to resize the frame. So there are three methods, Boolean pack_propagate(True/False) method prevents the resizing of the frame from the widget.resizable(x, y) method prevents the window to be resized.Pack(fill, expand) values which resize the window to its defined size in the geometry.Basically, all the widgets inside the tkinter frame will be responsive and cannot be resized.Examplefrom tkinter import * win= Tk() win.geometry("700x300") #Don't allow the screen to be resized win.resizable(0, 0) ... Read More

How to return a JSON object from a Python function in Tkinter?

Sarika Singh
Updated on 23-Nov-2022 07:50:53

2K+ Views

JavaScript Object Notation, or JSON is a simple data format that is used to exchange data between many different languages. It is simple to read for people and simple for computers to parse. Python reads JSON text as a quoted-string that contains the value in each key-value mapping. Once parsed, it is accessible in Python as a dictionary object. JSON data can be encoded and decoded using the built-in package json in Python. You must first import the json library in order to work with files of the json type. Purposeco JSON Python to JSON conversion is done using serialization. ... Read More

Advertisements