banner



How To Use An Image As A Background In Tkinter

How to add together background image in Python Tkinter

In this post, you will learn how to add together a background epitome in Python Tkinter.

Tkinter is a standard cross-platform package for creating graphical user interfaces (GUIs). It is as well called the Tk interface. It is an original GUI library for Tcl (Tool Command Language). Tkinter comes pre-installed with Python. The greatest force of Tkinter is its simplicity. There are different ways to add a groundwork paradigm. But always, a label widget is used to gear up the groundwork.

Add together a background image using PhotoImage()

The PhotoImage grade is used to brandish images in labels, buttons, canvases, and text widgets, which are nowadays in tkinter package. This function takes a file path as an statement and returns the image object. Nosotros tin place the geometry managing director that allows users to put the widget anywhere on the screen by providing x & y coordinates. The following code demonstrates this-

          from tkinter import * from PIL import ImageTk, Paradigm    app = Tk() app.championship("Welcome") img =Epitome.open('C:\\Python37\\scripts\\projects\\kittens.jpg') bg = ImageTk.PhotoImage(img)  app.geometry("650x450")  # Add image label = Label(app, image=bg) characterization.place(x = 0,y = 0)  # Add text label2 = Label(app, text = "How-do-you-do kittens",                font=("Times New Roman", 24))  label2.pack(pady = 50)  # Execute tkinter app.mainloop()        

Output of the above lawmaking: tkinter background image

Add a groundwork image using create_image()

In the given instance, we have added a background image using the create_image() method in the canvas widget. The Canvas is a rectangular expanse planned for drawing pictures or other complex layouts. We can put graphics, text, widgets, or frames on a Canvas. The create_image() method of Sail is used to draw an paradigm on a canvas. The create_image() function doesn't accept an image directly. Information technology uses an object which is created by the PhotoImage() method.

The process of adding a background image in Python Tkinter using the Canvas is almost the same every bit the above. Outset, we added the image file, then created a canvass and set the width and pinnacle. Then we take displayed the image using the create_image() role and set the text using the create_text() role.

          #Import the required library from tkinter import * from PIL import Image, ImageTk from tkinter import ttk  # Create object root = Tk()  # Define the geometry of the window root.geometry("500x450")  # Add the epitome file bg = ImageTk.PhotoImage(file="C:\\Python37\\scripts\\projects\\natural_img1.png")  # Create a sheet canvas = Canvas(root,width= 400, elevation= 300) sheet.pack(make full= "both", expand=Truthful)  # Display image sheet.create_image(0, 0, image=bg, anchor="nw")  # Add a text in canvas sheet.create_text(250,250,text="Practiced Morning!",                 font=("Times New Roman", 24))  # Execute tkinter root.mainloop()        

Output of the above lawmaking: tkinter background image

Related Manufactures

Countdown clock and timer using Tkinter in Python
Simple Calculator Program in Python
Python gmplot to add google map on a web folio
Python requests GET method
Python OpenCV ColorMap
Python three Tkinter Carte Bar
Python Tkinter Frame Widget
Python Tkinter Checkbutton Widget
Python Tkinter Combobox Event Binding
Python Tkinter Checkbutton Widget
Python Tkinter Combobox
Python Tkinter Text Widget
Entry Field Validation in Tkinter Python
Python Tkinter Scale Widget
Python Tkinter Overview and Examples
Python3 Tkinter Messagebox
Entry Field Validation in Tkinter Python
Python iii Tkinter Card Bar
Convert Python list to numpy array
Convert cord to list Python
Python programme to listing even and odd numbers of a list
Python loop through list
Sort list in descending society Python

How To Use An Image As A Background In Tkinter,

Source: https://www.etutorialspoint.com/index.php/543-how-to-add-background-image-in-python-tkinter

Posted by: sheppardanstor47.blogspot.com

0 Response to "How To Use An Image As A Background In Tkinter"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel