Python 3 Tkinter Script to Load & Display Images in Window From FileDialog Widget GUI Desktop App
34 views
Jun 3, 2025
Get the full source code of application here: https://codingshiksha.com/python/python-3-tkinter-script-to-load-display-images-in-window-from-filedialog-widget-gui-desktop-app/
View Video Transcript
0:00
uh hello guys welcome to this video so
0:02
in this video I will show you a very
0:04
important concept inside Twinter how to
0:07
take uh the user input and display the
0:10
images right in the window itself so we
0:13
have the simple Python twin desktop
0:16
application where we will allow the user
0:18
to simply select any sort of image from
0:21
their computer we have this button right
0:23
here open image as soon as you click
0:26
this button this file picker will window
0:29
will open here you can actually select
0:32
uh any image file that you want to
0:35
select as soon as you select the image
0:37
file the image will be displayed right
0:40
in the screen itself so I will show you
0:43
how to do this inside uh tweak framework
0:47
inside Python it's a very important task
0:50
because you want to accept user input so
0:53
whenever users select any file it will
0:56
display right in the window itself so
0:59
it's a image previewer image loader kind
1:02
of an
1:03
application i will show you all the
1:05
source code is given in the description
1:07
of the video so first of all you need to
1:09
import the tweer package by simply
1:12
writing from twe import
1:15
everything import star and then we'll be
1:18
using this pillow
1:21
library inside this library we have two
1:24
methods imagek and the image class so
1:28
just install this library by executing
1:31
this command pip install pillow this is
1:35
just go to the terminal and install this
1:37
command install this library after that
1:41
you
1:42
simply say from trick enter we need to
1:45
import the file dialogue
1:49
class and then we
1:52
simply define the window like this root
1:56
tk and then we set the properties about
1:59
the window which is the
2:02
title and then we set
2:05
the x coordinate and the y coord sorry
2:09
width and the height which is 500 by
2:12
500 and then we set root resizable you
2:17
can set the width to be true you can
2:20
resize the
2:22
window if you don't want to allow the
2:25
user to resize it you can put false here
2:28
and then we can simply add a button
2:31
inside the window which lets the user
2:34
opens the image picker window and we can
2:38
define this on click listener so when
2:41
whenever you hit this button we are
2:43
attaching this command here which is a
2:45
function custom function which will
2:48
execute open image and then we'll be
2:51
adding it in a grid-like
2:58
structure and then we start this
3:02
application so now we just need to
3:04
define this function open image so as
3:06
soon as you hit this
3:10
button so here we just need to open the
3:13
file picker window inside this function
3:16
so we
3:18
simply again define another function
3:20
here which will be open file name
3:30
so this will
3:33
actually open this file picker window by
3:36
using this file dialog class it contains
3:38
this function which is ask open file
3:42
name we just give it a title to this
3:45
window which will
3:51
be so here we will be getting the file
3:54
name and then we returning this file
3:56
name from this function so once we get
4:00
the file
4:01
name then we can display this image by
4:04
the image class of pillow we open this
4:08
image then we resize this
4:11
image to a fixed size
4:33
so essentially we are resizing the image
4:36
so that we can display properly inside
4:39
the window
4:41
then we use this image TK
4:46
class contains this photo image and we
4:50
embed this image inside this image
4:52
widget then we display this inside the
4:55
panel
5:11
we add this in the grid like
5:13
structure so this completes the
5:16
application so if I execute this
5:20
now click this select any image
5:30
so in this way you can actually build
5:33
this very simple application where we
5:35
allow the user to simply select any
5:37
image from their local file system and
5:39
display this right in the window itself
5:42
so thank you very much for watching this
5:44
video all the source code is given in
5:46
the description of the video and also
5:49
check out my website freemediatools.com
5:52
uh which
5:54
contains thousands of tools