{"id":99907,"date":"2021-02-24T11:00:00","date_gmt":"2021-02-24T09:00:00","guid":{"rendered":"https:\/\/examples.javacodegeeks.com\/?p=99907"},"modified":"2022-07-08T15:54:36","modified_gmt":"2022-07-08T12:54:36","slug":"python-gui-programming-with-tkinter","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/","title":{"rendered":"Python GUI Programming with Tkinter"},"content":{"rendered":"<p>In this article, we&#8217;re going to see one famous GUI on Python called: Tkinter library. Also, we&#8217;ll see some widgets used to build interfaces with this framework and create an example using it.<\/p>\n<p>You can also check this tutorial in the following video:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/www.youtube.com\/watch?v=MXKE_jrXwj4\"><img decoding=\"async\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Python-GUI-Programming-1024x576.jpg\" alt=\"\" class=\"wp-image-113863\" width=\"512\" height=\"288\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Python-GUI-Programming-1024x576.jpg 1024w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Python-GUI-Programming-300x169.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Python-GUI-Programming-768x432.jpg 768w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/07\/Python-GUI-Programming.jpg 1280w\" sizes=\"(max-width: 512px) 100vw, 512px\" \/><\/a><figcaption>Python GUI Programming &#8211; video<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-introduction\">1. Introduction<\/h2>\n<p><a href=\"https:\/\/docs.python.org\/3\/library\/tkinter.html\" target=\"_blank\" rel=\"noreferrer noopener\">Tkinter<\/a> library is a Python library to develop Graphical User Interface (GUI). It is embedded in the standard Python installation.<\/p>\n<p>One advantage of Tkinter is that it&#8217;s easy to use. Also, as a native Python language library, we just need to import and start coding to work.<\/p>\n<p>Furthermore, it\u2019s&nbsp;<strong>cross-platform<\/strong>, so the same code works on Windows, macOS, and Linux.<\/p>\n<p>In the next steps, we&#8217;ll see how to start a project and create a simple interface example.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-2-pre-requisites\">2. Pre-requisites<\/h2>\n<p>The examples found in this article work in version 3.6 or above. You can find the most recent version of Python to download <a href=\"https:\/\/www.python.org\/downloads\/\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n<p>Also, feel free to use any IDE\/Code Editor with support for Python language and versions recommended above.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-3-getting-started-with-the-python-tkinter-library\">3. Getting Started with the Python Tkinter library<\/h2>\n<p>First, let&#8217;s discuss some concepts about a GUI. In following, we have the most common:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>Container &#8211;<\/strong> it&#8217;s the component to organize and store our interface&#8217;s objects. Imagine a real-life container, where we put everything together. In this case, the objects that we want to store are the <strong>widgets.<\/strong><\/li>\n<li><strong>Widgets &#8211; <\/strong>it&#8217;s any screen&#8217;s element. Can be a button, a label, a textbox, an icon, etc&#8230;<\/li>\n<li><strong>Event Handler &#8211; <\/strong>it&#8217;s an action or routine that is executed when we click on a button for instance. <\/li>\n<li><strong>Event Loop &#8211; <\/strong>an event loop verifies if another event was added. When this condition is confirmed, the event loop will execute the correspondent routine.<\/li>\n<\/ul>\n<h3 class=\"wp-block-heading\" id=\"h-3-1-starting-a-simple-interface\">3.1 Starting a simple interface<\/h3>\n<p>The bottom example shows a simple interface created with the Tkinter library.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Simple Tkinter example<\/em><\/span><\/p>\n<pre class=\"brush:python\">from tkinter import *\n\nclass Application:\n    def __init__(self, master=None):\n        pass\nroot = Tk()\nApplication(root)\nroot.mainloop()\n<\/pre>\n<p>Let&#8217;s understand the code above:<\/p>\n<ol class=\"wp-block-list\">\n<li>Import all the component of Tkinter with <code>from tkinter import *<\/code><\/li>\n<li>Create the <code>Application<\/code> class to start our code where we put all the interface&#8217;s controls.<\/li>\n<li>Instantiate the <code>Tk()<\/code> class in the <code>root<\/code> variable. The <code>Tk()<\/code> class allows the widgets been used in the interface.<\/li>\n<li>Send the root as a parameter to the Application class constructor. <\/li>\n<li>To conclude, we call the method (event loop) <code>root.mainloop()<\/code> to show the screen. Without this event loop, the interface won&#8217;t be shown.  <\/li>\n<\/ol>\n<p>This code will create a very simple window when executed.<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkintersimple.png\"><img decoding=\"async\" width=\"500\" height=\"300\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkintersimple.png\" alt=\"tkinter python - example window\" class=\"wp-image-99948\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkintersimple.png 500w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkintersimple-300x180.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption>Tkinter simple example window<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-4-working-with-widgets\">4. Working with Widgets<\/h2>\n<h3 class=\"wp-block-heading\" id=\"h-4-1-container-explained\">4.1 Container explained<\/h3>\n<p>To work with widgets, it&#8217;s necessary to understand the concept of containers. Below is an example to help us:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/containerstructure.png\"><img decoding=\"async\" width=\"800\" height=\"400\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/containerstructure.png\" alt=\"tkinter python - container structure\" class=\"wp-image-100073\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/containerstructure.png 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/containerstructure-300x150.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/containerstructure-768x384.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption>Container structure<\/figcaption><\/figure>\n<\/div>\n<p>For a matter of organization, we define containers and inside each one, we put our widgets. Therefore, every time a container is created, we must define what is the <strong>top-level <\/strong>container.<\/p>\n<p>After defining the hierarchy of containers and widgets, we should position the elements on the screen, indicating the position where the element will appear.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-2-creating-a-widget\">4.2 Creating a widget<\/h3>\n<p>Now, talking about widgets, a class defines each&nbsp;one&nbsp;in Tkinter. Here are some of the widgets available:<\/p>\n<figure class=\"wp-block-table aligncenter is-style-stripes\">\n<table>\n<tbody>\n<tr>\n<td><strong>Widget<\/strong> <strong>class<\/strong><\/td>\n<td><strong>Description<\/strong><\/td>\n<\/tr>\n<tr>\n<td><code>Label<\/code><\/td>\n<td>A widget used to display text on the screen<\/td>\n<\/tr>\n<tr>\n<td>Button<\/td>\n<td>A button that can contain text and can perform an action when clicked<\/td>\n<\/tr>\n<tr>\n<td>Entry<\/td>\n<td>A text entry widget that allows only a single line of text<\/td>\n<\/tr>\n<tr>\n<td>Text<\/td>\n<td>A text entry widget that allows multiline text entry<\/td>\n<\/tr>\n<tr>\n<td>Frame<\/td>\n<td>A rectangular region used to group related widgets or provide padding between widgets<\/td>\n<\/tr>\n<\/tbody>\n<\/table><figcaption>Widget classes<\/figcaption><\/figure>\n<\/p>\n<p>In the bottom example, we&#8217;ll add our first widget in the code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Fist widget Tkinter example<\/em><\/span><\/p>\n<pre class=\"brush:python\">from tkinter import *\n\nclass Application:\n    def __init__(self, master=None):\n        self.container1 = Frame(master)\n        self.container1.pack()\n        self.msg = Label(self.container1, text=\"First widget\")\n        self.msg.pack()\nroot = Tk()\nApplication(root)\nroot.mainloop()\n<\/pre>\n<p>In the previous example, we add our first container using the <code>Frame<\/code> class. Next, we use the <code>pack()<\/code> method from the <code>Frame<\/code> class that defines the <strong>geometry management <\/strong>of our container. We&#8217;ll see more about geometry managers in the next sections.<\/p>\n<p>Following, adding a label widget we insert a simple text (&#8220;First widget&#8221;). And then, use the method pack(). <\/p>\n<p>Note that we put our previously created container (<code>container1<\/code>) in the <code>Label<\/code> class constructor to inform the code what&#8217;s the parent (top-level) container of the widget. <\/p>\n<p>And the result is here:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkinterfirstwidget.png\"><img decoding=\"async\" width=\"200\" height=\"200\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkinterfirstwidget.png\" alt=\"tkinter python - first widget example\" class=\"wp-image-100071\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkinterfirstwidget.png 200w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkinterfirstwidget-150x150.png 150w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkinterfirstwidget-70x70.png 70w\" sizes=\"(max-width: 200px) 100vw, 200px\" \/><\/a><figcaption>First widget example<\/figcaption><\/figure>\n<\/div>\n<p>Compared with our first example, when we don&#8217;t have any widget, the screen reduced its size. This happens because when we don&#8217;t have any content defined, the screen assumes the default size.<\/p>\n<p>However, when we insert some content (a widget for instance), the main window assumes the size of this element. As we didn&#8217;t define size in the <code>pack() <\/code>method, the screen assumed the widget size.<\/p>\n<h3 class=\"wp-block-heading\" id=\"h-4-3-geometry-management\">4.3 Geometry management<\/h3>\n<p>As we see before, after defining our containers and widget&#8217;s hierarchy, we should position those elements on the screen, indicating the position that the element will appear.<\/p>\n<p>For that, Tkinter has 3 options to use:<\/p>\n<h4 class=\"wp-block-heading\" id=\"h-4-3-1-pack\">4.3.1 Pack<\/h4>\n<p>In our previously first widget example, we use the <code>pack() <\/code>geometry manager, one of the most used.<\/p>\n<p>The pack places the widget in a&nbsp;<code>Frame<\/code>&nbsp;or window in a specified order. It computes a rectangular area (parcel) that holds the widget and fills the remaining window&#8217;s area with blank space.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Pack example<\/em><\/span><\/p>\n<pre class=\"brush:python\">import tkinter as tk\n\nwindow = tk.Tk()\n\nframe1 = tk.Frame(master=window, width=100, height=100, bg=\"red\")\nframe1.pack()\n\nframe2 = tk.Frame(master=window, width=50, height=50, bg=\"yellow\")\nframe2.pack()\n\nframe3 = tk.Frame(master=window, width=25, height=25, bg=\"green\")\nframe3.pack()\n\nwindow.mainloop()\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/pack.png\"><img decoding=\"async\" width=\"358\" height=\"349\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/pack.png\" alt=\"tkinter python - pack manager\" class=\"wp-image-100089\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/pack.png 358w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/pack-300x292.png 300w\" sizes=\"(max-width: 358px) 100vw, 358px\" \/><\/a><figcaption>Pack manager example<\/figcaption><\/figure>\n<\/div>\n<h4 class=\"wp-block-heading\" id=\"h-4-3-2-grid\">4.3.2 Grid<\/h4>\n<p>The <code>grid()<\/code> geometry manager is maybe more likely to use. It provides the same approach of <code>pack()<\/code>, but in an easier way to work and maintain. <\/p>\n<p>Imagine that we&#8217;re working with a table kind interface with columns and lines. The grid() method splits them in the Frame class.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Grid example<\/em><\/span><\/p>\n<pre class=\"brush:python\">import tkinter as tk\n\nwindow = tk.Tk()\n\nfor rw in range(3):\n    for cl in range(3):\n        frame = tk.Frame(\n            master=window,\n            relief=tk.RAISED,\n            borderwidth=1\n        )\n        frame.grid(row=rw, column=cl)\n        label = tk.Label(master=frame, text=f\"Row {rw}\\nColumn {cl}\")\n        label.pack()\n\nwindow.mainloop()\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridexample.png\"><img decoding=\"async\" width=\"358\" height=\"330\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridexample.png\" alt=\"\" class=\"wp-image-100128\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridexample.png 358w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridexample-300x277.png 300w\" sizes=\"(max-width: 358px) 100vw, 358px\" \/><\/a><figcaption>Grid example<\/figcaption><\/figure>\n<\/div>\n<p>We can notice that grid() is called on each frame object created and applied to the window object (top-level). <\/p>\n<p>Another change we can do is put some padding in our columns and lines, adding this on our code:<\/p>\n<p><span style=\"text-decoration: underline\"><em>Padding on grid example<\/em><\/span><\/p>\n<pre class=\"brush:python\">frame.grid(row=rw, column=cl, padx=5, pady=5)\n<\/pre>\n<p>And see the result here:<\/p>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridpadding.png\"><img decoding=\"async\" width=\"358\" height=\"330\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridpadding.png\" alt=\"\" class=\"wp-image-100127\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridpadding.png 358w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridpadding-300x277.png 300w\" sizes=\"(max-width: 358px) 100vw, 358px\" \/><\/a><figcaption>Grid manager with padding<\/figcaption><\/figure>\n<\/div>\n<p>Also, to work with resizing our window, we can add this line to make the window more &#8220;responsive&#8221; for our re-sizing.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Re-sizing grid example<\/em><\/span><\/p>\n<pre class=\"brush:python\">for rw in range(3):\n    window.columnconfigure(i, weight=1, minsize=75)\n    window.rowconfigure(i, weight=1, minsize=50)\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridresized.png\"><img decoding=\"async\" width=\"800\" height=\"470\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridresized.png\" alt=\"\" class=\"wp-image-100129\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridresized.png 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridresized-300x176.png 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/gridresized-768x451.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption>Grid re-sized<\/figcaption><\/figure>\n<\/div>\n<h4 class=\"wp-block-heading\" id=\"h-4-3-3-place\">4.3.3 Place<\/h4>\n<p>We can use <code>place()<\/code> manager to put an element in a specific place in our interface.<\/p>\n<p>Just specifying an x-y coordinate, we put our element in the position that we want to place our element.<\/p>\n<p><span style=\"text-decoration: underline\"><em>Place example<\/em><\/span><\/p>\n<pre class=\"brush:python\">import tkinter as tk\n\nwindow = tk.Tk()\n\nframe = tk.Frame(master=window, width=250, height=250, bg=\"white\")\nframe.pack()\n\nlabel1 = tk.Label(master=frame, text=\"I'm at (0, 0)\", bg=\"red\")\nlabel1.place(x=0, y=0)\n\nlabel2 = tk.Label(master=frame, text=\"I'm at (150, 150)\", bg=\"green\")\nlabel2.place(x=150, y=150)\n\nwindow.mainloop()\n<\/pre>\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/placeexample.png\"><img decoding=\"async\" width=\"500\" height=\"400\" src=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/placeexample.png\" alt=\"\" class=\"wp-image-100131\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/placeexample.png 500w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/placeexample-300x240.png 300w\" sizes=\"(max-width: 500px) 100vw, 500px\" \/><\/a><figcaption>Place example<\/figcaption><\/figure>\n<\/div>\n<h2 class=\"wp-block-heading\" id=\"h-5-simple-application-example\">5. Simple application example<\/h2>\n<p>I&#8217;ve attached in this article a simple application interface to create a user. There, we&#8217;ll see everything we used until here and store our data in a simple SQLite.<\/p>\n<p>SQLite is not the target of this article, so you don&#8217;t need to be concerned about that.<\/p>\n<p>The application is divided into layers as follows:<\/p>\n<ul class=\"wp-block-list\">\n<li><strong>App.py &#8211; <\/strong>is where we have our container and widgets of our application.<\/li>\n<li><strong>Users.py &#8211; <\/strong>is our model class for user data.<\/li>\n<li><strong>Db.py &#8211;<\/strong> is our database class to work with SQLite.<\/li>\n<\/ul>\n<p>The application calls <strong>user_register_app<\/strong> inside the examples .zip file.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-6-conclusion\">6. Conclusion<\/h2>\n<p>In conclusion, we saw the use of the Tkinter library to build interfaces in Python. Also, we could understand the concepts involving containers and widgets and see some examples to know how to use geometry management in our interfaces.<\/p>\n<h2 class=\"wp-block-heading\" id=\"h-7-download-the-source-code\">7. Download the source code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a href=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/tkinter_examples.zip\"><strong>Python GUI Programming with Tkinter<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this article, we&#8217;re going to see one famous GUI on Python called: Tkinter library. Also, we&#8217;ll see some widgets used to build interfaces with this framework and create an example using it. You can also check this tutorial in the following video: Python GUI Programming &#8211; video 1. Introduction Tkinter library is a Python &hellip;<\/p>\n","protected":false},"author":239,"featured_media":99891,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[46689],"tags":[46693,1716,46692],"class_list":["post-99907","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-python","tag-gui","tag-python","tag-tkinter"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python GUI Programming with Tkinter - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Tkinter library is a Python library to develop Graphical User Interface (GUI). It is embedded in the standard Python installation.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python GUI Programming with Tkinter - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Tkinter library is a Python library to develop Graphical User Interface (GUI). It is embedded in the standard Python installation.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-02-24T09:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-07-08T12:54:36+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sergio Lauriano Junior\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@sergiolauriano\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sergio Lauriano Junior\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/\"},\"author\":{\"name\":\"Sergio Lauriano Junior\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe\"},\"headline\":\"Python GUI Programming with Tkinter\",\"datePublished\":\"2021-02-24T09:00:00+00:00\",\"dateModified\":\"2022-07-08T12:54:36+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/\"},\"wordCount\":1186,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"keywords\":[\"gui\",\"python\",\"tkinter\"],\"articleSection\":[\"Python\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/\",\"name\":\"Python GUI Programming with Tkinter - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"datePublished\":\"2021-02-24T09:00:00+00:00\",\"dateModified\":\"2022-07-08T12:54:36+00:00\",\"description\":\"Tkinter library is a Python library to develop Graphical User Interface (GUI). It is embedded in the standard Python installation.\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg\",\"width\":150,\"height\":150,\"caption\":\"set python\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/web-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Python\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/web-development\/python\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Python GUI Programming with Tkinter\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe\",\"name\":\"Sergio Lauriano Junior\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg\",\"caption\":\"Sergio Lauriano Junior\"},\"description\":\"Sergio is graduated in Software Development in the University City of S\u00e3o Paulo (UNICID). During his career, he get involved in a large number of projects such as telecommunications, billing, data processing, health and financial services. Currently, he works in financial area using mainly Java and IBM technologies.\",\"sameAs\":[\"https:\/\/www.linkedin.com\/in\/sergio-lauriano\/\",\"https:\/\/x.com\/@sergiolauriano\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/sergio-lauriano\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python GUI Programming with Tkinter - Java Code Geeks","description":"Tkinter library is a Python library to develop Graphical User Interface (GUI). It is embedded in the standard Python installation.","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:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/","og_locale":"en_US","og_type":"article","og_title":"Python GUI Programming with Tkinter - Java Code Geeks","og_description":"Tkinter library is a Python library to develop Graphical User Interface (GUI). It is embedded in the standard Python installation.","og_url":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-02-24T09:00:00+00:00","article_modified_time":"2022-07-08T12:54:36+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","type":"image\/jpeg"}],"author":"Sergio Lauriano Junior","twitter_card":"summary_large_image","twitter_creator":"@sergiolauriano","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Sergio Lauriano Junior","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/"},"author":{"name":"Sergio Lauriano Junior","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe"},"headline":"Python GUI Programming with Tkinter","datePublished":"2021-02-24T09:00:00+00:00","dateModified":"2022-07-08T12:54:36+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/"},"wordCount":1186,"commentCount":0,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","keywords":["gui","python","tkinter"],"articleSection":["Python"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/","url":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/","name":"Python GUI Programming with Tkinter - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","datePublished":"2021-02-24T09:00:00+00:00","dateModified":"2022-07-08T12:54:36+00:00","description":"Tkinter library is a Python library to develop Graphical User Interface (GUI). It is embedded in the standard Python installation.","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2021\/02\/python-logo.jpg","width":150,"height":150,"caption":"set python"},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/python-gui-programming-with-tkinter\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/examples.javacodegeeks.com\/category\/web-development\/"},{"@type":"ListItem","position":3,"name":"Python","item":"https:\/\/examples.javacodegeeks.com\/category\/web-development\/python\/"},{"@type":"ListItem","position":4,"name":"Python GUI Programming with Tkinter"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/79f2e4070e5cb0ccb5fd87ab3ac1f9fe","name":"Sergio Lauriano Junior","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2020\/09\/sergio_photo-96x96.jpeg","caption":"Sergio Lauriano Junior"},"description":"Sergio is graduated in Software Development in the University City of S\u00e3o Paulo (UNICID). During his career, he get involved in a large number of projects such as telecommunications, billing, data processing, health and financial services. Currently, he works in financial area using mainly Java and IBM technologies.","sameAs":["https:\/\/www.linkedin.com\/in\/sergio-lauriano\/","https:\/\/x.com\/@sergiolauriano"],"url":"https:\/\/examples.javacodegeeks.com\/author\/sergio-lauriano\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/99907","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/239"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=99907"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/99907\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/99891"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=99907"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=99907"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=99907"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}