<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vin Mukiibi</title>
    <description>The latest articles on DEV Community by Vin Mukiibi (@akmukiibi).</description>
    <link>https://dev.to/akmukiibi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F482884%2Fa0cd15f4-a1b4-4450-871d-2b567049b781.png</url>
      <title>DEV Community: Vin Mukiibi</title>
      <link>https://dev.to/akmukiibi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akmukiibi"/>
    <language>en</language>
    <item>
      <title>Have dinner with Python's Tkinter Library tonight</title>
      <dc:creator>Vin Mukiibi</dc:creator>
      <pubDate>Mon, 05 Oct 2020 18:39:19 +0000</pubDate>
      <link>https://dev.to/akmukiibi/have-dinner-with-python-s-tkinter-library-tonight-2foj</link>
      <guid>https://dev.to/akmukiibi/have-dinner-with-python-s-tkinter-library-tonight-2foj</guid>
      <description>&lt;p&gt;Is there a more concise language than Python? Of course not, you and I know that. Lets explore Python's Tkinter library for developing wonderful and good looking Graphical User interfaces. It has beautiful documentation at the link below&lt;br&gt;
&lt;a href="https://docs.python.org/3/library/tk.html"&gt;https://docs.python.org/3/library/tk.html&lt;/a&gt; . The docs shall tell you the story, as for us, lets dive right in with a practical introduction to tkinter.&lt;br&gt;
This tutorial assumes that you know Python basics, already have a cool Python IDE (I personally prefer JetBrain's PyCharm) and a heart for learning python, especially Tkinter.&lt;/p&gt;

&lt;p&gt;The plan&lt;br&gt;
Our plan is to have you build your home town's people directory, and that shall be our deliverable. A user should be able to add a person onto the directory, update any person, remove a person and clear the directory at a go. We all know the proverbial CRUD introduction. Lets get our feet wet.&lt;/p&gt;

&lt;p&gt;Algorithm&lt;br&gt;
All programs follow a procedure, you should have it in your mind even before you write a single line of code. As they normally say, coding is 90% thinking, 5% writing code, and 5% sipping on your cup of tea/coffee (whatever you prefer, I prefer tea). &lt;br&gt;
This is what we want&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HOs3TqSA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zyg7jtb90lzxsprvoem6.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HOs3TqSA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zyg7jtb90lzxsprvoem6.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So we gonna first define our UI i.e. the input elements, buttons etc (VIEW), then we gonna think about how to store our data (MODEL), then we gonna put our logic into the UI to send our data to the database (CONTROLLER). We have talked too much, lets start, follow the comments.&lt;/p&gt;

&lt;p&gt;Lets first import our tkinter library and a few other dependencies&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--VNJ9FqWf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y8r4p7zr13nekpz3k0bs.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--VNJ9FqWf--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/y8r4p7zr13nekpz3k0bs.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--htt-Euab--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rdnw4uotfefcmlh3td79.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--htt-Euab--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/rdnw4uotfefcmlh3td79.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we gonna define our widgets&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uxHyUWdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/km7xxxfvqe12jdi1vlgb.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uxHyUWdh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/km7xxxfvqe12jdi1vlgb.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
Feel free to define the last widget which is for the contact&lt;/p&gt;

&lt;p&gt;Now this is where it gets interesting, we define our listbox where we shall view our people, then attach a scrollbar to it vertically&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lLgNt9q5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zd7zccn9z5txu49t4gxe.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lLgNt9q5--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/zd7zccn9z5txu49t4gxe.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then we gonna put our buttons&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--I-YuyTQz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mnp3y6fnja2cd6xqn87o.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--I-YuyTQz--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/mnp3y6fnja2cd6xqn87o.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That is all for the UI, concerning the database, we shall store our data in an sqlite database whose code  have already written, download it for free at &lt;a href="https://github.com/akmukiibi/py-tkinter-pirple/blob/master/db.py"&gt;https://github.com/akmukiibi/py-tkinter-pirple/blob/master/db.py&lt;/a&gt; JUST MAKE SURE ITS IN THE SAME DIRECTORY AS YOUR MAIN FILE.&lt;/p&gt;

&lt;p&gt;Lets move onto the logic i.e. controller bit&lt;br&gt;
We need to write a few functions that gonna invoke our db api after collecting user input or user events on our buttons.&lt;/p&gt;

&lt;p&gt;Lets fetch all our people in the directory and put them in the listbox&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--BCs4Ics1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gvc9i1fgyvic7h43joc1.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--BCs4Ics1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gvc9i1fgyvic7h43joc1.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now lets add a user to the db by writing a function to invoke the db.py&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ClScY9m8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o0v7xlmcvdm6cblqrhvh.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ClScY9m8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o0v7xlmcvdm6cblqrhvh.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then lets write a function to select an item once  clicked on the listbox&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sgyh00iU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v4cv0npaavofdxjifxpw.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sgyh00iU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/v4cv0npaavofdxjifxpw.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets update and delete a person from the list, feel free to write the function that clears the inputs on your own. We learn by doing, right??&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--56vfdQYN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r3cl84rzxu9icssz6ho3.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--56vfdQYN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/r3cl84rzxu9icssz6ho3.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, lets populate the list and start our window GUI&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--YbIyMz5r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l0709ptrqpzce5yzi53t.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--YbIyMz5r--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/l0709ptrqpzce5yzi53t.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Bingo&lt;/p&gt;

&lt;p&gt;Find the full code on github at  &lt;a href="https://github.com/akmukiibi/py-tkinter-pirple"&gt;https://github.com/akmukiibi/py-tkinter-pirple&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>python</category>
      <category>tkinter</category>
      <category>introduction</category>
      <category>pirple</category>
    </item>
  </channel>
</rss>
