how to put a background image in tkinter python GUI | Put background image in python/pycharm GUI

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] okay guys it's me imart from nelson darwin park tech youtube channel so today we are going to learn about how to put an image on the background of tkinter gui so tkinter is a built-in tool within the python so that we can make some sort of gui's within this tool so we will import two packages from two libraries from teacher import static from tick enter means that from the tkinter library we need to import all the things uh because static simply means that whatsoever we want to import we can okay are all the functions and methods are exposed to our programming programming window okay so from tkinter import star and from pil pil is another library import image tk comma image so these two are the functions from this pil library now after import import of two libraries we need to go for our gui making and that is we have to first declare a variable variable is simple like anything any word you can write anything here even one alphabet like m a b c or anything will act as a variable here on left hand side here so we have written master as a variable now this is a variable master is equal to tk so tk is our built-in function built-in function of tkinter library and it will create one gui for us and all the now all because we have equalized this library to a variable that is the master variable so all of our attributes and all all the properties are now like a are our likeness are being inserted into this variable that is the master after this thing we need to give the title of this gui so we will write master.title okay it is our title our project okay we will just write project project so this is our title of our gui now we have to write one more variable that is uh called as image underscore 0 is equal to now we will for what we have declared this variable because we want to insert all the all the image all the all the information and data regarding image into this variable so how we can uh do it uh we have one built-in function that is called as image dot open image dot open and within the parentheses we need to give the link of our image image is the sub module of library pil and open is the function that lies within the image submodule and open function will open the uh file for us like the file of image so we will go for like our whereas our image we will go for e drive okay so we will go to e drive we will go for like here okay f we grow plant yard and here we have soil fertility meter so we will go to its properties we will copy its link control c again we need to go to here paste it link spray place one slash and after the placing of slash we need to go to copy the name and type of this meter okay so we write this and dot jb g okay one more thing that you need to write the double slashes rather than single slashes okay so this is our image now we need to run it out okay they said no such file directory dot jpg okay so okay wait let me let me see it properly that either is there any sort of like problem okay jpeg we have to rectify one more thing image dot open and colon slay slash okay okay now we need to run it out okay now it is actually jpg rather than jpg so it's we have written the extension wrong after this thing we have to go for the next step and that is the that is to define another variable so whatsoever you want to write here it will act as a variable so we need to write pck underscore end that is backend and it is variable you can write anything here what it needs to do is to that whatsoever we will perform on the right hand side of this uh is equal to uh it will it will like this assignment operator will assign all the things to this variable that is backend so we will go for like image tk image tk this is our mhtk dot photo image dot photo image image underscore 0 image underscore 0 so now what is this this function or this is sub module image tk from pil library and dot photo image is the function of this uh sub module it will take this image it will take this image and it will then store all the things that whatsoever done because these two functions used to perform some sort of action on this parameter that is image underscore 0 and then they will give it to the back underscore and variable ok now now we will write master.geometry because we have to define the length and width of our gui master dot geometry so we have written 800 cross 600 800 cross 600 okay but master or bad geometry specified they said 800 cross 600 okay okay we have to uh write across rather than static okay so it is right now uh 800 is the length and 600 is the width of our gui now we will uh put the two labels level mean that uh which are like uh labels are just for just like the title subtitles and text okay so label lbl is our first variable so with the help of this very variable we will make one level so we will write lbel label and after it we will write master master comma image is equal to bck underscore g and d okay oh sorry e and d rather than g and d so it is why it is so because but what it will shows actually l a b a b e l is our a built-in function of our tick into gui it will create label but where on the master gui okay master is the name of our gui and image is equal to back underscore and we have to write or we have to insert the image which is inside the back and backend variable okay now if we used to write lbl.place because we also need to place it at a proper place lbl dot place x equal to 0 y is equal to 0 because we don't want to like uh translate this or move on x axis or y axis so that is why we have mentioned x equal to zero and y is equal to zero okay after rest we we need to write master dot main loop master dot main loop and like this okay so okay you know we okay now you can see that our uh background images here so obviously we have to place if you want to place some other things on it we can okay so let us let uh like place the second label if you want okay we can even place some button but uh still it is okay we can place label lbl2 is equal to label label master comma comma text is equal to master comma text is equal to like hello world so we will write hello project hello project so so here you can see the title is our what's called as the project okay we also need to pick this label as well okay so level two dot back we we have to do level two peg function is actually used for to like uh hold the label on specific location okay level two dot pick and we need to write in its parameters label two dot peg parameters p a d y is equal to 50 that is if you want to move it y axis on like because it needs to like make some sort of difference between one widget and other widget so that is why we use write paid y and all this so okay now you can see that our hello project is written there so even you can make some of your functions some of your widgets on this gui but as this is for just to ensure the background for the tkinter gui so you can make your background ggi with the help of this so hopefully you got the concept so thanks for visiting our channel and don't forget to subscribe
Info
Channel: Nelson Darwin Pak Tech
Views: 24,134
Rating: undefined out of 5
Keywords: how to put a background image in tkinter GUI., background image in python/pycharm GUI., tutorial on how to insert a picture in the background of tkinter/python GUI., simplest program to insert background image in pycharm GUI, easiest code to put background image in python/pycharm GUI, how to insert a background image in python tkinter GUI
Id: fsL8oZXiJmY
Channel Id: undefined
Length: 11min 26sec (686 seconds)
Published: Tue Dec 28 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.