Found 26504 Articles for Server Side Programming

Select all text in a Text widget using Python 3 with tkinter

Dev Prakash Sharma
Updated on 16-Apr-2021 07:16:35

2K+ Views

Tkinter text widgets are used for creating text fields that contain multiline user input. It has many inbuilt functions and methods which can be invoked to perform certain operations on text widgets. In contrast, let us assume that we have written a bunch of context in the text widget and if we want to select all the text, then we can use tag_add(tag, range) to select the text and add tag and tag_configure(tag, options) to style the tag property.Example#Import tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry win.geometry("750x200") def select_text(): ... Read More

Resizing pictures in PIL in Tkinter

Dev Prakash Sharma
Updated on 16-Apr-2021 07:14:47

825 Views

Python provides Pillow or PIL package for image processing which is used to load, process, and customize the images in an application. It has many properties like Color of the image, Image Font, resizing the images, loading the image, etc.In order to resize the Images in an application, we can use the resize(width, height) method. The method can be invoked after loading the image in the application. In order to open the image in the application, we have to import the package in the notebook as, from PIL import Image, ImageTkExampleIn the following example, we have resized an image to ... Read More

Save File Dialog Box in Tkinter

Dev Prakash Sharma
Updated on 20-Aug-2021 16:20:01

14K+ Views

We often use Open and Save Dialog. They are common across many applications and we already know how these dialogs work and behave. For instance, if we click on open, it will open a dialog to traverse the location of the file. Similarly, we have the Save Dialog.We can create these dialogs using Python tkFileDialog package. In order to work with the package, we have to import this in our environment.Type the following command to import the tkFileDialog package in the notebook, from tkinter.filedialog import asksaveasfileExampleIn this example, we will create an application that will save the file using the ... Read More

Removing minimize/maximize buttons in Tkinter

Dev Prakash Sharma
Updated on 16-Apr-2021 07:11:30

5K+ Views

When we run our tkinter application, it initially displays a window that has an interface to display all the widgets. Eventually, we can remove the maximizing and minimizing property of the displayed window by using the resizable(boolean) method. It takes two Boolean values that refer to the status of width and height of the window. We generally disable the max and min resizing property by assigning zero to both values of width and height.Example#Import the required library from tkinter import* #Create an instance of tkinter frame win= Tk() #Set the geometry win.geometry("750x250") #Disable the resizable Property win.resizable(False, False) #Create an ... Read More

Notebook widget in Tkinter

Dev Prakash Sharma
Updated on 16-Apr-2021 07:10:10

5K+ Views

Notebook widget is an inbuilt widget of ttk library in tkinter. It enables the user to create Tabs in the window application. Tabs are generally used to separate the workspace and specialize the group of operations in applications at the same time.ExampleIn this example, we will create two tabs using Notebook widget and then will add some context to it.#Import the required library from tkinter import * from tkinter import ttk #Create an instance of tkinter frame win = Tk() win.geometry("750x250") #Create a Notebook widget my_notebook= ttk.Notebook(win) my_notebook.pack(expand=1, fill=BOTH) #Create Tabs tab1= ttk.Frame(my_notebook) my_notebook.add(tab1, text= "Tab 1") tab2= ttk.Frame(my_notebook) my_notebook.add(tab2, ... Read More

How to update a Python/tkinter label widget?

Dev Prakash Sharma
Updated on 22-Jul-2021 13:02:37

3K+ Views

Tkinter comes with a handy built-in functionality to handle common text and images related objects. A label widget annotates the user interface with text and images. We can provide any text or images to the label widget so that it displays in the application window.Let us suppose that for a particular application, we need to update the label widget. A label widget is a container that can have either text of image. In the following example, we will update the label image by configuring a button.Example#Import the required library from tkinter import * from PIL import Image, ImageTk from tkinter ... Read More

How to use an image for the background in tkinter?

Dev Prakash Sharma
Updated on 16-Apr-2021 07:06:46

3K+ Views

Background images in tkinter are versatile as the functionality can be used in making 3D, 2D games, screensaver, desktop visualizations software, etc. Tkinter canvas is used to work with all these functionalities in an application.ExampleIn this example, we will add a background image using the create_image() method in the canvas widget.#Import the required library from tkinter import * from PIL import Image, ImageTk from tkinter import ttk #Create an instance of tkinter window win= Tk() #Define the geometry of the window win.geometry("750x650") #Load the image bg= ImageTk.PhotoImage(file="./tutorialspoint.png") #Create a canvas canvas= Canvas(win, width= 400, height= 200) canvas.pack(expand=True, fill= BOTH) #Add the ... Read More

How to use a custom font in Tkinter?

Dev Prakash Sharma
Updated on 16-Apr-2021 07:05:03

2K+ Views

To define and display a custom font in Python tkinter, we generally use an inbuilt font library defined in tkinter. In order to import the tkinter Font library in the notebook, type the following in the shell, from tkinter.font import FontNow, create an Object of Font using the Font(..options) function and define other properties of the font such as font-family, size, weight, slant, underline, strike, etc.Example#Import the required library from tkinter import * #Create an instance of tkinter frame win = Tk() win.geometry("750x250") #Create a String Object and set the default value var = StringVar() #Create a text label label ... Read More

How to update an image in a Tkinter Canvas?

Dev Prakash Sharma
Updated on 16-Apr-2021 07:00:49

12K+ Views

Canvas can be used to play with images, animating objects, 3D modeling, displaying text, and many more. Moreover, we can display an image file using the create_image() constructor.Following this, let us build an application that can update the canvas images locally. We can add a button to trigger the event which when pressed will change the canvas image.To change a particular image, we can configure the canvas by using the itemconfig() constructor. It takes image files which need to be updated and displayed them on the window.Use three images of your choice and save them in the same project directory.Example#Import ... Read More

How to set focus on Entry widget in Tkinter?

Dev Prakash Sharma
Updated on 16-Apr-2021 06:58:25

8K+ Views

Let us suppose that there are some widgets present in an application such that we have to focus on a particular widget. By using the focus_set() method, we can activate the focus on any widget and give them priority while executing the application.Example#Import tkinter library from tkinter import * #Create an instance of tkinter frame win = Tk() #Set the geometry of tkinter window win.geometry("750x250") #Create an Entry Widget entry= Entry(win, width= 25) entry.insert(0, "ttk Entry widget") entry.pack() #Set the focus to Entry widget entry.focus_set() win.mainloop()OutputWhen we run our program, it will display a window with ... Read More

Advertisements