Found 604 Articles for Tkinter

Removing minimize/maximize buttons in Tkinter

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

4K+ 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

3K+ 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

2K+ 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

10K+ 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

6K+ 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

How to update the image of a Tkinter Label widget?

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

5K+ Views

We have used Label widget to group all the widgets in the application. A Label widget takes text and images in the constructor that sets the label with the position in the top-left corner of the window. However, to change or update the image associated with the Label, we can use a callable method where we provide the information of other images.ExampleIn the following example, we will create a button to update the Label image.#Import the required library from tkinter import* from PIL import Image, ImageTk #Create an instance of tkinter frame win= Tk() #Define geometry of the ... Read More

How to position Tkinter widgets so that they are not stuck together?

Dev Prakash Sharma
Updated on 16-Apr-2021 06:54:51

281 Views

In a tkinter GUI skeleton, we can add any number of widgets to make it more functional and operational. However, sometimes, it seems difficult to resize and position the widgets so that they don’t stick together and are non-variable in size. We can add padding using the widget pack manager to make every widget stand as one separate entity.Example#Import the required library from tkinter import* from tkinter import ttk #Create an instance of tkinter frame win= Tk() #Set the geometry win.geometry("750x250") #Create an Label Widget Label(win, text= "New Line Text", font= ('Helvetica 15 underline')).pack(pady=20) left=Button(win, text="Button1", font= ... Read More

How to interactively validate an Entry widget content in tkinter?

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

1K+ Views

Validating the content is a necessary part of any featured application where we allow only the required data to be processed. An Entry Widget in tkinter is used to display single line text Input. However, we can validate the Entry widget to accept only digits or alphabets.Let us first create an Entry widget that accepts only digits input. So initially, we will create an Entry widget and using register(callback) function, we will call to validate the Entry widget which validates whenever a key is stroked. It returns a string that can be used to call a function. Then, calling the ... Read More

Advertisements