In Tkinter, users can input text using two basic text input widgets − the Text widget and the Entry widget. The Text widget is generally used to accept multiline user input, whereas in an Entry widget, the user can type only singleline text.You can customize these widgets and add additional functionality using built-in library functions and methods. To validate the input in an Entry widget, you can use the register() method. This method returns a string that can be used to call the function at later stages.To validate the input in an Entry widget, use the config(**options) method and pass ... Read More
The Canvas widget is one of the versatile widgets in Tkinter which is used to create illustrations, draw shapes, arcs, images, and other complex layouts in an application. To create a Canvas widget, you'll need to create a constructor of canvas(root, **options).You can use the factory functions to create text, images, arcs and define other shapes in the canvas. In some cases, if you want to create another canvas using the same canvas to keep the application workflow consistent, then you can create a button to call an event that creates another canvas.To understand this, let us create a canvas ... Read More
We are already familiar with input forms where various single Entry fields are created to capture the user input. With Tkinter, we can also create a single input field using the Entry widget. Each character in the Entry field that the user enters is indexed. Thus, you can retrieve this index to get the current position of the cursor by using the index() method. To retrieve the current location of the cursor, you can pass the INSERT argument in this function.Example# Import required libraries from tkinter import * from tkinter import ttk # Create an instance of tkinter window ... Read More
Tkinter offers several built-in functions and class library methods to build components and user-actionable items of an application. filedialog is one of the tkinter modules that provides classes and library functions to create file/directory selection windows. You can use filedialog where you need to ask the user to browse a file or a directory from the system.You can also specify the location of the directory from where a particular file should be picked up. To display the filedialog that starts from a particular location, use the initialdir = argument in the static factory function askopenfilename(initialdir=). This function creates a ... Read More
Padding enhances the layout of the widgets in an application. While developing an application in Tkinter, you can set the padding in two or more ways. The geometry manager in Tkinter allows you to define padding (padx and pady) for every widget (label, text, button, etc). To set the application component and its properties look and feel consistent, you can define the values in a variable. The values can be further used to define the padding of the widgets. Let us understand this with an example.ExampleIn the following example, we will create a frame inside which the widgets are defined. ... Read More
The Toplevel window is an option to create a child window in an application. It works similar to the default main tkinter window. We can configure the size of a Toplevel window, customize its properties and attributes as well as add widgets that we want to build the component with.For a particular application, if we have defined a Toplevel window, then we can close it using the destroy() method.ExampleIn the following example, we have created an application that contains a button to open a Toplevel window. The Toplevel window or child window contains a label text and a button to ... Read More
We use various geometry managers to place the widgets on a tkinter window. The geometry manager tells the application where and how to organize the widgets in the window. With geometry manager, you can configure the size and coordinates of the widgets within the application window.The pack() method in tkinter is one of the three geometry managers. The other geometry managers are grid() and place(). The pack() geometry manager is commonly used to provide padding and a way to arrange the widgets in the window.To configure the properties and attributes of a widget explicitly after defining it, you can use ... Read More
The Entry widget is used to accept single-line text strings from users.Text widget − Displays multiple lines of text that can be edited.Label widget − Displays one or more lines of text that cannot be modified by the user.Importing tkinter, csv and creating the main window. Name the output window "Data Entry"(any name for output window) and Create three functions based on the output you need. Here the function of add, save and clear is built in to make the buttons work functionally.After providing the input in the window, click the add button. The add function will display a message ... Read More
To use a floating image in HTML, use the CSS property float. It allows you to float an image left or right. More property values include the following:Sr.No.Property Value & Description1noneNot floated2leftFloats to the left3rightFloats to the right4initialDefault valueExampleYou can try to run the following code to use floating image in HTML. Here’s the usage of float right and float left CSS attribute HTML Floating Image Float Right The below image floats to the right. This is demo text. ... Read More
The sqrtm() function of scipy.linalg package can be used to find the square root of an input matrix.Syntaxscipy.linalg.sqrtm(x)Example 1Let us consider the following example −# Importing the required libraries from scipy from scipy import linalg import numpy as np # Define the input array x = np.array([[14 , 2] , [89 , 33]]) print("Input array:", x) # Calculate the square root r = linalg.sqrtm(x) # Display the square root print("Square Root of x: ", r)OutputIt will generate the following output −Input array: [[14 2] [89 33]] Square Root of x: [[3.43430132 0.22262855] [9.90697038 5.54927253]]Example 2Let us take ... Read More