

{"id":113511,"date":"2023-04-03T09:00:48","date_gmt":"2023-04-03T03:30:48","guid":{"rendered":"https:\/\/data-flair.training\/blogs\/?p=113511"},"modified":"2026-06-01T12:56:38","modified_gmt":"2026-06-01T07:26:38","slug":"python-image-viewer","status":"publish","type":"post","link":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/","title":{"rendered":"Python Image Viewer \u2013 Where Images Meet Innovation"},"content":{"rendered":"<p>With the help of a forward and backward button, users can navigate between images in the Image Viewer App. Let&#8217;s follow a few simple steps to construct an Image Viewer Project in Python.<\/p>\n<h3>About Python Image Viewer<\/h3>\n<p>In this project, we&#8217;re going to create a Tkinter module-based image viewer project. The PIL module will also be used to perform operations on the images. The user can navigate through a list of images using the app.<\/p>\n<h3>What is Tkinter?<\/h3>\n<p>Python offers various utilities to design the GUI wiz Graphical User Interface, and one such utility is Tkinter which is most commonly used. It is one of the fastest and easiest ways to build GUI applications. Moreover, Tkinter is cross-platform. As a result, the same code works on macOS, Windows, and Linux.<\/p>\n<h3>Prerequisites for Image Viewer using Python<\/h3>\n<ul>\n<li>Basic knowledge of Python Programming Language and how function is defined in it.<\/li>\n<li>How the window is made in Tkinter GUI , and how the frame is made in it.<\/li>\n<\/ul>\n<h3>Download Python Image Viewer Code<\/h3>\n<p>Please download the source code for python image viewer project from the following link: <a href=\"https:\/\/drive.google.com\/file\/d\/1cikeyRyvhPx9Fu3aywm_zUNZVbvmV15L\/view?usp=drive_link\"><strong>Python Image Viewer Project Code\u00a0<\/strong><\/a><\/p>\n<h3>Steps to Create the Python Image Viewer Project<\/h3>\n<p>Following are the steps for developing the Image Viewer project:<\/p>\n<h4>Step 1: Importing the necessary modules<\/h4>\n<p>To use Tkinter, we need to import the Tkinter module. We are also going to import the zipfile and filedialog module.<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#import packages\r\nfrom tkinter import *\r\nimport tkinter as tk\r\nfrom PIL import ImageTk, Image\r\n<\/pre>\n<h4>Step 2: Making a window for our project<\/h4>\n<p>This code sets the title of the window as \u2018DataFlair Image Viewer Appr\u2019, and sets the dimensions as resizable.<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#creating window\r\nroot = tk.Tk()\r\nroot.title(\"DataFlair Image Viewer App\")\r\nroot.resizable()\r\n<\/pre>\n<h4>Step 3: Functions<\/h4>\n<p>This function takes images to be displayed in the form of a list and runs a loop for them on that list so that users can navigate through their images.<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#creating label to display images \r\nj = 0\r\nimg_label = Label(frame, image=List_img[j])\r\nimg_label.pack()\r\n#function for next image\r\ndef next_img():\r\n   global j\r\n   j = j + 1\r\n   try:\r\n       img_label.config(image=List_img[j])\r\n   except:\r\n       j = -1\r\n       next_img()\r\n#function for prev image\r\ndef prev():\r\n   global j\r\n   j = j - 1\r\n   try:\r\n       img_label.config(image=List_img[j])\r\n   except:\r\n       j = 0\r\n       prev()\r\n<\/pre>\n<p><strong>Explanation<\/strong><\/p>\n<p><strong>def next_img()<\/strong> is used for the next image, and <strong>def prev()<\/strong> for the previous image. def next_img() <strong>\u201c j = j + 1\u201d<\/strong> is used to move forward in the list, and in def prev() <strong>\u201cj = j &#8211; 1\u201d<\/strong> to move backward in the list of images by configuring the label (img_label) we made to display images. The <strong>\u2018except\u2019<\/strong> condition in both functions is used if there is no next or previous image, respectively, in the list.<\/p>\n<h4>Step 4: Making a frame to display images<\/h4>\n<p>We make a frame and in that frame a label to display images, and we also make a list of images through which we can navigate.<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#fame to display images\r\nframe = tk.Frame(root)\r\nframe.pack(pady=10)\r\n\r\n\r\nimg_1 = ImageTk.PhotoImage(Image.open(\"1.jpg\"))\r\nimg_2 = ImageTk.PhotoImage(Image.open(\"2.jpg\"))\r\nimg_3 = ImageTk.PhotoImage(Image.open(\"3.png\"))\r\nimg_4 = ImageTk.PhotoImage(Image.open(\"4.png\"))\r\nList_img = [img_1, img_2, img_3, img_4]\r\n\r\n\r\nj = 0\r\nimg_label = Label(frame, image=List_img[j])\r\nimg_label.pack()\r\n<\/pre>\n<h4>Step 5: Making Frames and Mapping the Buttons to Their Functionalities<\/h4>\n<p>We make two frames, and in one frame we make two buttons, Next and Previous, to navigate in the list of images, and in the second frame we make an exit button to exit the app.<\/p>\n<p><strong>Code<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#creating frame for previous, next, and exit button\r\nframe1 = tk.Frame(root)\r\nframe1.pack(pady=5)\r\nPrev = tk.Button(frame1, text=\"Previous\", command=prev)\r\nPrev.pack(side=\"left\", padx=10)\r\nNext = tk.Button(frame1, text=\"Next\", command=next_img)\r\nNext.pack(side=\"right\", padx=10)\r\n\r\n\r\nframe2 = tk.Frame(root)\r\nframe2.pack(pady=5)\r\nExit = tk.Button(frame2, text=\"Exit\", command=root.quit)\r\nExit.pack(side=\"bottom\")\r\n\r\n\r\nroot.mainloop()<\/pre>\n<p><strong>Full Code<\/strong><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">#import packages\r\nfrom tkinter import *\r\nimport tkinter as tk\r\nfrom PIL import ImageTk, Image\r\n#creating window\r\nroot = tk.Tk()\r\nroot.title(\"DataFlair Image Viewer App\")\r\nroot.resizable()\r\n#fame to display images\r\nframe = tk.Frame(root)\r\nframe.pack(pady=10)\r\n\r\n\r\nimg_1 = ImageTk.PhotoImage(Image.open(\"1.jpg\"))\r\nimg_2 = ImageTk.PhotoImage(Image.open(\"2.jpg\"))\r\nimg_3 = ImageTk.PhotoImage(Image.open(\"3.png\"))\r\nimg_4 = ImageTk.PhotoImage(Image.open(\"4.png\"))\r\nList_img = [img_1, img_2, img_3, img_4]\r\n#creating label to display images \r\nj = 0\r\nimg_label = Label(frame, image=List_img[j])\r\nimg_label.pack()\r\n\r\n\r\n#function for next image\r\ndef next_img():\r\n   global j\r\n   j = j + 1\r\n   try:\r\n       img_label.config(image=List_img[j])\r\n   except:\r\n       j = -1\r\n       next_img()\r\n\r\n\r\n#function for prev image\r\ndef prev():\r\n   global j\r\n   j = j - 1\r\n   try:\r\n       img_label.config(image=List_img[j])\r\n   except:\r\n       j = 0\r\n       prev()\r\n\r\n\r\n#creating frame for previous, next, and exit button\r\nframe1 = tk.Frame(root)\r\nframe1.pack(pady=5)\r\nPrev = tk.Button(frame1, text=\"Previous\", command=prev)\r\nPrev.pack(side=\"left\", padx=10)\r\nNext = tk.Button(frame1, text=\"Next\", command=next_img)\r\nNext.pack(side=\"right\", padx=10)\r\n\r\n\r\nframe2 = tk.Frame(root)\r\nframe2.pack(pady=5)\r\nExit = tk.Button(frame2, text=\"Exit\", command=root.quit)\r\nExit.pack(side=\"bottom\")\r\n\r\n\r\nroot.mainloop()<\/pre>\n<h3>Python Image Viewer Output<\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-113515 size-full alignnone\" src=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/python-image-viewer-output.webp\" alt=\"python image viewer output\" width=\"1128\" height=\"915\" \/><\/p>\n<h3>Summary<\/h3>\n<p>We have successfully created an Image Viewer App using Python Tkinter GUI. Now one can easily navigate through their images. This project provides practical exposure to various python libraries such as Tkinter to make a nice GUI, ImageTk, and image to open the images and display them.<span hidden class=\"__iawmlf-post-loop-links\" data-iawmlf-links=\"[{&quot;id&quot;:2567,&quot;href&quot;:&quot;https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1cikeyRyvhPx9Fu3aywm_zUNZVbvmV15L\\\/view?usp=drive_link&quot;,&quot;archived_href&quot;:&quot;http:\\\/\\\/web-wp.archive.org\\\/web\\\/20260601072621\\\/https:\\\/\\\/drive.google.com\\\/file\\\/d\\\/1cikeyRyvhPx9Fu3aywm_zUNZVbvmV15L\\\/view?usp=drive_link&quot;,&quot;redirect_href&quot;:&quot;&quot;,&quot;checks&quot;:[{&quot;date&quot;:&quot;2026-06-02 07:07:51&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-05 16:32:35&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-17 21:44:43&quot;,&quot;http_code&quot;:200},{&quot;date&quot;:&quot;2026-06-22 13:49:59&quot;,&quot;http_code&quot;:200}],&quot;broken&quot;:false,&quot;last_checked&quot;:{&quot;date&quot;:&quot;2026-06-22 13:49:59&quot;,&quot;http_code&quot;:200},&quot;process&quot;:&quot;done&quot;}]\"><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>With the help of a forward and backward button, users can navigate between images in the Image Viewer App. Let&#8217;s follow a few simple steps to construct an Image Viewer Project in Python. About&#46;&#46;&#46;<\/p>\n","protected":false},"author":581,"featured_media":113749,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46],"tags":[27416,27415,27414,27413,27242,21095,21073],"class_list":["post-113511","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-image-viewer","tag-image-viewer-project","tag-python-image-viewer","tag-python-image-viewer-project","tag-python-project-for-practice","tag-python-project-ideas","tag-python-projects"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Python Image Viewer \u2013 Where Images Meet Innovation - DataFlair<\/title>\n<meta name=\"description\" content=\"Transform the way you view and manipulate images with our innovative Python image viewer project. Discover the power of Python image viewing!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/data-flair.training\/blogs\/python-image-viewer\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python Image Viewer \u2013 Where Images Meet Innovation - DataFlair\" \/>\n<meta property=\"og:description\" content=\"Transform the way you view and manipulate images with our innovative Python image viewer project. Discover the power of Python image viewing!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/data-flair.training\/blogs\/python-image-viewer\/\" \/>\n<meta property=\"og:site_name\" content=\"DataFlair\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/DataFlairWS\/\" \/>\n<meta property=\"article:published_time\" content=\"2023-04-03T03:30:48+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2026-06-01T07:26:38+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/python-image-viewer-2.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"628\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"DataFlair Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:site\" content=\"@DataFlairWS\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"DataFlair Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python Image Viewer \u2013 Where Images Meet Innovation - DataFlair","description":"Transform the way you view and manipulate images with our innovative Python image viewer project. Discover the power of Python image viewing!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/","og_locale":"en_US","og_type":"article","og_title":"Python Image Viewer \u2013 Where Images Meet Innovation - DataFlair","og_description":"Transform the way you view and manipulate images with our innovative Python image viewer project. Discover the power of Python image viewing!","og_url":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/","og_site_name":"DataFlair","article_publisher":"https:\/\/www.facebook.com\/DataFlairWS\/","article_published_time":"2023-04-03T03:30:48+00:00","article_modified_time":"2026-06-01T07:26:38+00:00","og_image":[{"width":1200,"height":628,"url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/python-image-viewer-2.webp","type":"image\/webp"}],"author":"DataFlair Team","twitter_card":"summary_large_image","twitter_creator":"@DataFlairWS","twitter_site":"@DataFlairWS","twitter_misc":{"Written by":"DataFlair Team","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/#article","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/"},"author":{"name":"DataFlair Team","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445"},"headline":"Python Image Viewer \u2013 Where Images Meet Innovation","datePublished":"2023-04-03T03:30:48+00:00","dateModified":"2026-06-01T07:26:38+00:00","mainEntityOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/"},"wordCount":514,"commentCount":0,"publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/python-image-viewer-2.webp","keywords":["image viewer","image viewer project","python image viewer","python image viewer project","python project for practice","python project ideas","Python Projects"],"articleSection":["Python Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/data-flair.training\/blogs\/python-image-viewer\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/","url":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/","name":"Python Image Viewer \u2013 Where Images Meet Innovation - DataFlair","isPartOf":{"@id":"https:\/\/data-flair.training\/blogs\/#website"},"primaryImageOfPage":{"@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/#primaryimage"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/#primaryimage"},"thumbnailUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/python-image-viewer-2.webp","datePublished":"2023-04-03T03:30:48+00:00","dateModified":"2026-06-01T07:26:38+00:00","description":"Transform the way you view and manipulate images with our innovative Python image viewer project. Discover the power of Python image viewing!","breadcrumb":{"@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/data-flair.training\/blogs\/python-image-viewer\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/#primaryimage","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/python-image-viewer-2.webp","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2023\/03\/python-image-viewer-2.webp","width":1200,"height":628,"caption":"python image viewer"},{"@type":"BreadcrumbList","@id":"https:\/\/data-flair.training\/blogs\/python-image-viewer\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog Home","item":"https:\/\/data-flair.training\/blogs\/"},{"@type":"ListItem","position":2,"name":"Python Tutorials","item":"https:\/\/data-flair.training\/blogs\/category\/python\/"},{"@type":"ListItem","position":3,"name":"Python Image Viewer \u2013 Where Images Meet Innovation"}]},{"@type":"WebSite","@id":"https:\/\/data-flair.training\/blogs\/#website","url":"https:\/\/data-flair.training\/blogs\/","name":"DataFlair","description":"Learn Today. Lead Tomorrow.","publisher":{"@id":"https:\/\/data-flair.training\/blogs\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/data-flair.training\/blogs\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/data-flair.training\/blogs\/#organization","name":"DataFlair","url":"https:\/\/data-flair.training\/blogs\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/","url":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","contentUrl":"https:\/\/data-flair.training\/blogs\/wp-content\/uploads\/sites\/2\/2016\/07\/Data-Flair.png","width":106,"height":48,"caption":"DataFlair"},"image":{"@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/DataFlairWS\/","https:\/\/x.com\/DataFlairWS","https:\/\/www.linkedin.com\/company\/dataflair-web-services-pvt-ltd\/","https:\/\/www.youtube.com\/user\/DataFlairWS"]},{"@type":"Person","@id":"https:\/\/data-flair.training\/blogs\/#\/schema\/person\/c187795dc82ab948373cca526df7c445","name":"DataFlair Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/2302ebc438084d2f1f993edc1996a0aae01332e81f3227cba8df0c48ec010ca4?s=96&d=mm&r=g","caption":"DataFlair Team"},"description":"DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.","url":"https:\/\/data-flair.training\/blogs\/author\/dfteam6\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/113511","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/users\/581"}],"replies":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/comments?post=113511"}],"version-history":[{"count":15,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/113511\/revisions"}],"predecessor-version":[{"id":148647,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/posts\/113511\/revisions\/148647"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media\/113749"}],"wp:attachment":[{"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/media?parent=113511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/categories?post=113511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/data-flair.training\/blogs\/wp-json\/wp\/v2\/tags?post=113511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}