Found 604 Articles for Tkinter

How to get the widget name in the event in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:37:34

2K+ Views

Tkinter is a Python library that is used to create and develop functional GUI-based applications. Tkinter provides widgets that can be used for constructing the visual and functional representation of the application.Let us suppose that we have defined some widgets in our application. If we want to get a widget's name in an event, then it can be achieved by using event.widget["text"] keywords inside a function. We can print the name by using it inside the print() function.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set ... Read More

How to delete lines from a Python tkinter canvas?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:34:33

3K+ Views

The Canvas widget has many use-cases in GUI application development. We can use a Canvas widget to draw shapes, creating graphics, images, and many other things. To draw a line in Canvas, we can use create_line(x, y, x1, y1, **options) method. In Tkinter, we can draw two types of lines − simple and dashed.If you want your application to delete the created lines, then you can use the delete() method.ExampleLet us have a look at the example where we will delete the line defined in the Canvas widget.# Import the required libraries from tkinter import * # Create an ... Read More

How to insert the current time in an Entry Widget in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:31:55

2K+ Views

To work with the date and time module, Python provides the 'datetime' package. Using the 'DateTime' package, we can display the date, manipulate the datetime object and use it to write the additional functionality in the application.To display the current date in a Tkinter window, we've to first import the datetime module in our environment. Once imported, you can create an instance of its object and display it using the Entry widget.ExampleHere is an example of how you can show the current date in an Entry widget.# Import the required libraries from tkinter import * import datetime as dt ... Read More

How to display an image/screenshot in a Python Tkinter window without saving it?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:27:38

1K+ Views

Tkinter is a standard Python library that is used to create and develop GUI-based applications. To display an image, we use the PIL or Pillow library.Let us suppose that we want to create an application that will take a screenshot of the window and display the captured image in another window. To achieve this, we can follow the steps given below −Import the required libraries.Create a universal button to take the screenshot.Define a function to take the screenshot.In the given function, define the coords and region through which we want to take the screenshot.Create a Toplevel window and define a ... Read More

How to draw a line on a Tkinter canvas?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:24:26

18K+ Views

Tkinter Canvas widget can be used for multiple purposes such as drawing shapes, objects, creating graphics and images. To draw a line on a Canvas, we can use create_line(x, y, x1, y1, **options) method.In Tkinter, we can draw two types of lines: simple and dashed. We can specify the type of line using the dash property.Example# Import the required libraries from tkinter import * # Create an instance of tkinter frame or window win=Tk() # Set the size of the tkinter window win.geometry("700x350") # Create a canvas widget canvas=Canvas(win, width=500, height=300) canvas.pack() # Add a line ... Read More

Resizing images with ImageTk.PhotoImage with Tkinter

Dev Prakash Sharma
Updated on 06-Aug-2021 06:22:43

20K+ Views

The PIL or Pillow library in Python is used for processing images in a Tkinter application. We can use Pillow to open the images, resize them and display in the window. To resize the image, we can use image_resize((width, height) **options) method. The resized image can later be processed and displayed through the label widget.ExampleLet us have a look at the example where we will open an image and resize it to display in the window through the label widget.# Import the required libraries from tkinter import * from PIL import Image, ImageTk # Create an instance of tkinter ... Read More

How to change Entry.get() into an integer in Tkinter?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:20:46

16K+ Views

The Entry widget in Tkinter is generally used to accept one-line input in the text field. We can get the output from the Entry widget using .get() method. However, the .get() method returns the output in string format. For example, if the user types an integer number in the Entry widget, it gets converted to a string. To change the type of the Entry input into an integer, we can cast the string to an integer.ExampleIn this example, we have shown how to calculate the sum while taking an integer input from the user.# Import the required libraries from tkinter ... Read More

How to configure default Mouse Double-Click behavior in a Tkinter text widget?

Dev Prakash Sharma
Updated on 06-Aug-2021 06:15:17

449 Views

The Text widget in Tkinter is used to add a text editor-like functionality in the application. The Text widget supports multiline user input from the user. We can configure the text widget properties such as its font properties, text color, background, etc., by using the configure() method.The Text widget also provides tagging through which we can make a selection of text. To extend this functionality, we can also bind the Double-Click button that will possess the event for selecting a Word at a time.ExampleLet us have a look at the example, where we have disabled the double mouse-click button to ... Read More

How to hide a widget after some time in Python Tkinter?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:48:51

538 Views

Tkinter is a standard Python library for developing GUI-based applications. We can create games, tools, and other applications using the Tkinter library. To develop GUI-based applications, Tkinter provides widgets.Sometimes, there might be a requirement to hide a widget for some time. This can be achieved by using the pack_forget() method. When we pack the widget in the window using the various methods, we have to use the same method for hiding the widget.Example# Import the required libraries from tkinter import * from PIL import Image, ImageTk # Create an instance of tkinter frame or window win=Tk() # Set ... Read More

How to change the TKinter canvas line from dash to solid?

Dev Prakash Sharma
Updated on 05-Aug-2021 14:46:48

453 Views

Canvas widget is one of the most widely used widgets for graphical representation in a Tkinter application. To display a line in the Canvas widget, we can use the built-in library method create_line(x1, y1, x2, y2, **options).We can also specify the type of line using the dash property. To change the line type from solid to dash dynamically, we can use configure() method. By passing an empty value to the dash property, we can change the line from solid to dash.ExampleLet us take an example to see how it works.# Import the required libraries from tkinter import * from tkinter ... Read More

Advertisements