<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Jasenko Krejić on Medium]]></title>
        <description><![CDATA[Stories by Jasenko Krejić on Medium]]></description>
        <link>https://medium.com/@krejjas?source=rss-d0a1eab05ce8------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*2P6kmmzNSZnx0vL5D29O5w.jpeg</url>
            <title>Stories by Jasenko Krejić on Medium</title>
            <link>https://medium.com/@krejjas?source=rss-d0a1eab05ce8------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 05:31:09 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@krejjas/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How I Passed the PCPP1 Exam]]></title>
            <link>https://medium.com/@krejjas/how-i-passed-the-pcpp1-exam-aa2e67b3e481?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/aa2e67b3e481</guid>
            <category><![CDATA[certification]]></category>
            <category><![CDATA[pcpp1]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Thu, 22 Oct 2026 12:39:40 GMT</pubDate>
            <atom:updated>2026-10-22T12:39:40.487Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*7Db8SUom07A0ULJt2aDW4Q.png" /></figure><p>I am glad and proud to announce that last week, I passed my PCPP1 exam!</p><p><a href="https://pythoninstitute.org/pcpp1">https://pythoninstitute.org/pcpp1</a></p><p>Currently, it is the highest available Python Institute certification, since PCPP2 was supposed to be released some time ago but has never actually appeared.</p><p>How did I pass it? I started studying for it about half a year ago, although I can’t say that my learning was continuous. I started by going through the syllabus, as I always do. It covers the following broad topics (taken from the official syllabus):</p><p>- Advanced OOP</p><p>- Best Practices and Standardization</p><p>- GUI Programming</p><p>- Network Programming</p><p>- File Processing and Communicating with a Program’s Environment</p><p>These are also the names of the official free courses on the pythoninstitute.org website. I followed them for a while before giving up on them. These courses are not bad, but I find that they sometimes lack focus on the really important things and spend too much time on less important ones. Besides that, navigation is a bit confusing. So, after reading what I thought was worth reading, I started studying on my own, following the syllabus topics. I soon found out that although these topics have impressive-sounding names, they can be a bit misleading. I like to make my own examples and explain things to myself as if I were explaining them to someone else. After all, I am an aspiring Medium writer and Python teacher, both online and in person.</p><p>I have to say that by the time I finished writing about and going through all the topics, the Word document where I kept my notes had grown to something like 110 pages. With a few more examples, it could become a decent book. I certainly didn’t expect so much material!</p><p>Then came the questions. I focused on two online quiz courses on Udemy:</p><p><a href="https://www.udemy.com/course/pcpp1-become-certified-professional-in-python-programming-1/">https://www.udemy.com/course/pcpp1-become-certified-professional-in-python-programming-1/</a></p><p><a href="https://www.udemy.com/course/pcpp1-certified-professional-in-python-programming/">https://www.udemy.com/course/pcpp1-certified-professional-in-python-programming/</a></p><p>The first one has 270 questions, and the second one has a total of 420. Both were quite demanding and prepared me well for what was to come on the actual exam. They contain some questions that may seem more appropriate for the previous PCAP associate-level exam, but they helped me memorize and refresh topics that I would need for PCPP1. I had the best time with advanced OOP topics and the worst time with XML and coding conventions. But that’s just me. Someone else might find coding conventions interesting and OOP complicated.</p><p>My biggest concern was the timing. I expected 65 minutes to be quite tight for 45 questions, especially when dealing with screens full of classes, methods, and code in some of the test questions. In fact, the exam turned out to be quite relaxed in terms of time, and I finished the questions I knew how to answer in about one-third of the allotted time. A few questions I wasn’t sure about were answered using the “educated guess” method, and I passed! Maybe going through all those quiz questions was overkill, but I have a feeling that without them, I might just as easily have failed.</p><p>My advice: study hard, learn as much as you can, first the concepts (OOP especially), and then try to remember as many details as possible in topics such as Tkinter and PEPs. I don’t think you can pass using only one of these approaches, because this exam requires you to understand the concepts well enough to apply them to something you haven’t seen before, while also remembering quite a few specific details. Also, once you’ve gone through all those quizzes and learned the concepts, schedule the exam! After a certain point, you might simply be overlearning, and you will still encounter some questions you’ve never seen before or have no idea whether the correct answer is B, C, or D.</p><p>I hope this helps you!</p><p>Happy learning!</p><p><strong>If you found this article helpful, consider supporting my work with a </strong><a href="https://ko-fi.com/jasenko/donate"><strong>small donation</strong></a><strong> on Ko-fi:<br></strong><a href="https://ko-fi.com/jasenko/donate"><strong>https://ko-fi.com/jasenko/donat</strong></a>e</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/0*b87Wj7CBMX8kgy6Q.png" /></figure><p>f you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">AWS Certified Cloud Practitioner Crash Course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=aa2e67b3e481" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python Generators: A Practical Explanation]]></title>
            <link>https://medium.com/@krejjas/python-generators-a-practical-explanation-4aa337d7c0f8?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/4aa337d7c0f8</guid>
            <category><![CDATA[generator]]></category>
            <category><![CDATA[python3]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[iterators]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Thu, 24 Sep 2026 08:21:21 GMT</pubDate>
            <atom:updated>2026-09-24T08:21:21.470Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WzAXIl9_Rs1lAG_cOJQTIA.png" /></figure><p>Generators are not, as you might first think, some kind of electrical device that generates electrical energy. In Python, a generator is a piece of code that generates a sequence of values and provides them one at a time, without storing all of them at once.</p><p>It is like a coffee machine that gives us a cup of coffee on request, but does not keep all the cups of coffee prepared inside it.It would be a waste of resources, and coffee would cool down.</p><p>We have seen something very similar to generator with <em>range()</em> function. It is something called<em> iterable,</em> which means it can be iterated with for example <em>for</em> loop. It does not store all values, but yields them on demand. Did I just say <em>yields,</em> as in <em>provide, return, result</em>? Yes, and we will use it soon.</p><p>But what type of object is a generator? Generator is a special object, returned by a generator function. That function must contain exactly <em>yield</em> to be classified as a generator function.</p><p>First, let us look at an example of a generator. First, let us define a function:</p><pre>def sequence(n):<br>    for i in range(n):<br>        return i<br>print(sequence(5))</pre><p>What will be the result of this program when we call it with argument 5? Can you guess?</p><p>You are probably familiar with <em>range(5)</em>, which will produce:</p><pre>0, 1, 2, 3, 4</pre><p>but not 5, since upper limit is not included.</p><p>But, this time, the output will be:</p><pre>0</pre><p>Why only zero?</p><p>Because when <em>i = 0</em>, the function executes:</p><pre>return 0</pre><p>and immediately exits the whole function, not just current iteration.</p><p>This is inconvenient because it does not go through the remaining values at all.</p><p>Let us move one step forward and say that if we replace <em>return</em> with something called <em>yield</em>, we will be able to obtain all these values from the loop.</p><p>The word <em>yield</em> can be understood as something that is produced or returned — an output or result.</p><p>If we replace return with yield:</p><pre># return i<br>yield i</pre><p>and print the function output value:</p><pre>print(sequence(5))</pre><p>we will get something like:</p><pre>&lt;generator object sequence at 0x000001A7B61AC2B0&gt;</pre><p><em>sequence(5)</em> is a generator, while <em>sequence</em> is a generator function.</p><p><em>range(1, 5)</em> is not a list, but a list-like object — it is a generator .It is similar to a list because we can use a for loop to obtain all of its elements.</p><p>Similar to <em>range</em> object, we can not directly print the <em>sequence(5)-</em> we must use for loop to iterate through its elements- kind of.</p><p>Kind of, because this generator object does not contain the elements themselves — it generates them whenever we request them.</p><p>Therefore, a generator is a function that contains yield, and when it is called, it becomes a generator. Or more formally, a generator object. We can assign it to a variable named, appropriately, <em>generator.</em></p><pre>generator = sequence(5)</pre><p>Now, we can check what is the type of <em>generator.</em></p><pre>print(type(generator))<br>&lt;class &#39;generator&#39;&gt;</pre><p>That is why we need a for loop to access elements inside generator. Each iteration of the for loop triggers one iteration of the loop inside the function and returns one value.</p><pre>for number in generator:<br>    print(number)<br>0<br>1<br>2<br>3<br>4</pre><p>A generator produces values lazily — one at a time, when we request them.</p><p>It does not generate entire list in advance and then iterate over that list with another <em>for</em> loop.</p><p>Instead, every time we move to the next element, the function remembers where it stopped and provides the next result using yield.</p><p>If we generated a list in advance and then used a for loop to retrieve its elements, we would first have to create the entire list.</p><p>If the list were very large, this could require a significant amount of memory.</p><p>If we try to iterate through the generator again, what will we get?</p><pre>for number in generator:<br>    print(number)<br>for number in generator:<br>    print(number)</pre><p>Second time, nothing will be printed- the loop will not even come to print, since <em>generator</em> contains nothing now. It is empty ,and applying <em>for</em> on an empty <em>something</em> will not execute indented code.</p><p>This happens because the generator becomes exhausted, and we have to generate it again:</p><pre>generator = sequence(5)</pre><p>There is no way to revert the sequence to beginning. This is different from, for example, file handler, when we can use <em>seek(0)</em> after <em>read</em> to position cursor at the beginning again.</p><p>We can also directly obtain a list or tuple from a generator, using built-in <em>list/tuple</em> function. That way, we don’t have to do something like create an empty list/tuple and sequentially add elements to it.</p><pre>print(list(sequence(5)))<br>[0, 1, 2, 3, 4]</pre><p>Or:</p><pre>print(tuple(sequence(5)))<br>(0, 1, 2, 3, 4)</pre><p>It is similar to a list comprehension expression inside square brackets, except that we use parentheses instead.</p><pre>numbers_list = [x for x in range(1, 5)]<br>print(numbers_list)<br>[1, 2, 3, 4]</pre><p>Here, <em>[x ….]</em> is called list comprehension, and the expression inside [g isa called just <em>expression.</em></p><p>But if we do this?</p><pre>numbers = (x for x in range(1, 5))</pre><p>You might have expected that we would get tuple instead of list if we used (), instead of [], but it is not the case.</p><pre>print(numbers)<br>&lt;generator object &lt;genexpr&gt; at 0x000001818641CC40&gt;<br>print(type(numbers))<br>&lt;class &#39;generator&#39;&gt;</pre><p>What we got, it also a generator- the one that is very similar to <em>generator</em> we defined manually with generator function <em>sequence.</em></p><p>Now that we have a generator <em>numbers, </em>we can use either <em>for </em>loop or <em>list</em> to get access to elements, like we did with <em>generator</em> generator object.</p><pre>for number in numbers:<br>    print(number)<br>1<br>2<br>3<br>4</pre><p>Stop for a moment, and think: what will this line of code return?</p><pre>print(list(numbers))</pre><p>It will output:</p><pre>[]</pre><p>Now, can you remember why? Of course, the generator <em>numbers </em>is exhausted, no more elements to generate, and we only get an empty list. We must recreate it again- numbers- to be able to use it.</p><pre>numbers = (x for x in range(1, 5))</pre><p>Generator objects are a special type of iterators, which are yet another interesting topic. Iterators, and therefore generators as well, can be used with <em>next </em>function. If we do:</p><pre>number =next(numbers)<br>print(number)<br>1</pre><p><em>next()</em> fetches just one element from the generator. Just like getting a cup of coffee from a coffee machine. If we do it again, we will get another cup….I mean, element.</p><pre>number = next(numbers)<br>print(number)<br>2</pre><p>And so on. And if we add enough <em>next</em>s, we will eventually get an error after 4 is printed:</p><pre>    number = next(numbers)<br>             ^^^^^^^^^^^^^<br>StopIteration</pre><p>With a for loop, we do not see this error because the loop automatically stops when the generator reaches the end.</p><p>But <em>next</em> has an option to provide default value instead of raising an exception if end is reached- it is a second, optional, argument. For a line that would otherwise cause a <em>StopIteration</em> error:</p><pre>number = next(numbers, &quot;EXAUSTED!&quot;)<br>print(number)<br>EXAUSTED!</pre><p>You may be surprised, but the same applies with <em>sequence()</em> function we defined earlier. Even though we did not implement anything like <em>next. </em>That is because the moment Python sees <em>yield</em> in a function, it use it as generator function and adds <em>next</em> to its generator.</p><p>I hope this article helped you to understand the basic of generators, which can be very confusing at times, with similar concepts like iterators, comprehensions getting in the way.</p><p>To recap: a generator in Python produces values lazily, one at a time, using <em>yield</em>, which makes it memory-efficient and allows iteration with for loops or next() without storing all values in advance. Similar to coffee machine yielding one coffee at time, not storing them all at once. Generators, as you have seen, can be created either as a result of calling a generator function(the one that contains <em>yield</em>) or a generator expression. Once all their values have been read, or how it is usually called, “consumed”, they become exhausted and must be recreated to be used again.</p><p><strong>If you found this article helpful, consider supporting my work with a </strong><a href="https://ko-fi.com/jasenko/donate"><strong>small donation</strong></a><strong> on Ko-fi:<br></strong><a href="https://ko-fi.com/jasenko/donate"><strong>https://ko-fi.com/jasenko/donat</strong></a>e</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/0*Xbe1b1DISfzZcSwm.png" /></figure><p>If you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4aa337d7c0f8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Slash and Other Strange Things in Python Function Definitions]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@krejjas/the-slash-and-other-strange-things-in-python-function-definitions-3aa01bc0b7da?source=rss-d0a1eab05ce8------2"><img src="https://cdn-images-1.medium.com/max/975/1*Da12Hu_uZMIfIcXMuZ55ug.png" width="975"></a></p><p class="medium-feed-snippet">I am currently preparing for a PCPP1 exam, and among the questions I encountered in preparation exam, was the following:</p><p class="medium-feed-link"><a href="https://medium.com/@krejjas/the-slash-and-other-strange-things-in-python-function-definitions-3aa01bc0b7da?source=rss-d0a1eab05ce8------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@krejjas/the-slash-and-other-strange-things-in-python-function-definitions-3aa01bc0b7da?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aa01bc0b7da</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[pcpp1]]></category>
            <category><![CDATA[arguments]]></category>
            <category><![CDATA[parameter]]></category>
            <category><![CDATA[function]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Wed, 02 Sep 2026 14:03:17 GMT</pubDate>
            <atom:updated>2026-09-02T14:03:17.583Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Using Tkinter Listbox Widget]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://medium.com/@krejjas/using-tkinter-listbox-widget-3c1298113cfa?source=rss-d0a1eab05ce8------2"><img src="https://cdn-images-1.medium.com/max/941/1*3qtXK9MpkOC1XPPeNWEUuw.png" width="941"></a></p><p class="medium-feed-snippet">The Tkinter Listbox widget is used to display a collection of items from which the user can select one or more entries. It is useful in&#x2026;</p><p class="medium-feed-link"><a href="https://medium.com/@krejjas/using-tkinter-listbox-widget-3c1298113cfa?source=rss-d0a1eab05ce8------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://medium.com/@krejjas/using-tkinter-listbox-widget-3c1298113cfa?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c1298113cfa</guid>
            <category><![CDATA[tkiinter]]></category>
            <category><![CDATA[widget]]></category>
            <category><![CDATA[listbox]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[gui]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Wed, 02 Sep 2026 08:27:34 GMT</pubDate>
            <atom:updated>2026-09-02T08:29:17.577Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Binding Mouse Actions to Tkinter Widgets]]></title>
            <link>https://medium.com/@krejjas/binding-mouse-actions-to-tkinter-widgets-450161aefacd?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/450161aefacd</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[tkinter]]></category>
            <category><![CDATA[data-binding]]></category>
            <category><![CDATA[gui]]></category>
            <category><![CDATA[widget]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Mon, 31 Aug 2026 10:29:24 GMT</pubDate>
            <atom:updated>2026-08-31T10:29:24.730Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*g0eMrBOZskvtgKTOiMd38w.png" /></figure><p><em>Tkinter</em> widgets can react to much more than just commands associated with a Button. By using the bind() method, we can connect functions to different events that occur on a widget.</p><p>In this article, we will focus specifically on mouse interaction with Tkinter widgets. We will look at events such as entering or leaving a widget, moving the mouse pointer, clicking mouse buttons, releasing them, double-clicking, and moving the mouse while a button is held down.</p><p>Keyboard events can also be handled with <em>bind()</em>, but they are a little more peculiar because they depend on keyboard focus. For that reason, key presses and keyboard-related events will be covered separately in another article.</p><p>The general form of a <em>bind()</em> method of a widget named <em>widget</em> is:</p><pre>widget.bind(&quot;event&quot;, function)</pre><p>Event is the action on a widget like a left mouse click, key press or a combination of those(but not limited to these), and <em>function </em>is a function that is executed when this event happens.</p><pre>import tkinter as tk<br>root = tk.Tk()<br>def click(event):<br>    print(&quot;Clicked!&quot;)<br><br><br>label = tk.Label(root, text = &quot;Click me!&quot;)<br>label.bind(&quot;&lt;Button-1&gt;&quot;, click)<br>label.pack()<br>root.mainloop()<br></pre><p>After running the program, we can see a familiar initial minimal Tkinter window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/1*5unZBqV664YMwO1n3dwo3A.png" /></figure><p>You can see that strange<em> Button-1</em> , surrounded by <em>less-than/greater-than</em>, it is just a fancy way to define left mouse click. So it applies only to a left mouse click. If we wanted any mouse button, we would use <em>&lt;Button&gt;</em>.When we click a label, a text will be printed on a console. You can see that we have passed(implicitly) <em>event</em> when we called function-lets print this <em>event </em>inside a function.</p><pre>print(event)<br>&lt;ButtonPress event num=1 x=35 y=12&gt;</pre><p>If we click the mouse button while holding for example, SHIFT:</p><pre>&lt;ButtonPress event state=Shift num=1 x=5 y=8&gt;</pre><p><em>State,</em> not very intuitively, shows which control keys(SHIFT,Alt) was pressed. We see <em>num = 1,</em> 1 for a left mouse button, and <em>x </em>and y coordinates of a point where mouse pointer was placed when the button was pressed. <em>x</em> is horizontal, and <em>y</em> vertical coordinate, from the upper left corner of the widget.</p><p>What if we press right mouse button? Nothing, it would not be triggered- remember, we use &lt;Button-1&gt; to target specifically left mouse button. Using <em>&lt;Button&gt;,</em> we would catch any mouse button click, and get <em>num =3 </em>for right mouse button. Similarily, we would use <em>&lt;Button-3&gt; </em>to check specifically for a right mouse button.</p><pre>label.bind(&quot;&lt;Button-3&gt;&quot;, click)</pre><p>There is even a way to check middle mouse button, and its number is-you guessed it-2, so &lt;Button-2&gt; will be used.</p><p>Clicking a mouse button involves pressing the mouse button, and then releasing it. We can not only trigger a mouse click event, but also on press and on release events. Let me show you:</p><pre>def mouse_press(event):<br>    print(event)<br>def mouse_release(event):<br>    print(event)<br>label.bind(&quot;&lt;ButtonPress-1&gt;&quot;, mouse_press)<br>label.bind(&quot;&lt;ButtonRelease-1&gt;&quot;, mouse_release)<br>&lt;ButtonPress event num=1 x=6 y=11&gt;<br>&lt;ButtonRelease event state=Button1 num=1 x=6 y=11&gt;</pre><p>You can click not only once, but two or three times- there are events for this as well.Suppose you want to exit the whole application when button is double click.</p><pre>def double(event):<br>    print(event)<br>    exit()<br>label.bind(&quot;&lt;Double-Button-1&gt;&quot;,double</pre><p>There is a triple click as well, but you must click very fast: <em>&lt;Triple-Button-1&gt;.</em> Rememebr,<em>-1</em> stands for left mouse button, if you want to catch any mouse button, just use <em>&lt;Double-Button&gt;/&lt;Tripple-Button&gt;.</em></p><p>And as the last event dealing with regular mouse clicks, there is an event that is generated when mouse button is pressed and pointer is moved:</p><pre>def clicked_moved(event):<br>    print(event)<br>label.bind(&quot;&lt;B1-Motion&gt;&quot;, clicked_moved)<br>&lt;Motion event state=Button1 x=29 y=6&gt;</pre><p>Strangely, there isn’t a unified command that detects any mouse button pressed while movig- you must use separate commands <em>&lt;B1-Motion&gt;, &lt;B2-Motion&gt; </em>and <em>&lt;B3-Motion&gt;.</em></p><p>Most of mice have a mouse wheel, and we can also use it to send an event. This event is called <em>MouseWheel.</em></p><pre>def wheel(event):<br>    print(event)<br>label.bind(&quot;&lt;MouseWheel&gt;&quot;, wheel)</pre><p>It triggers an event, and acts differently based on whether wheel was scrolled forward or backwards.</p><pre>&lt;MouseWheel event send_event=True delta=-120 x=35 y=5&gt;<br>&lt;MouseWheel event send_event=True delta=120 x=35 y=5&gt;</pre><p>You can see that <em>delta </em>parameter show the direction(+ forward, — backwards) and the numerical value of scroll, usually 120 for one wheel notch on windows. You may ask: can we get these numbers, as well as x and y coordinates, some other way, not only in the output when printing <em>event</em>? Yes, you can very easily get any parameter that you see in <em>print(event)</em> output by accessing the as variables of the <em>event </em>object.</p><pre>    print(event.delta)<br>    print(event.x, event.y)<br>-120<br>43 17</pre><p>Now things can get much more useful, because you can use these numbers to do all kind of calculation, and for interaction between widgets.</p><p>We can even detect that the mouse has moved over the widget with the motion event.</p><pre>def move(event):<br>    print(event)<br>label.bind(&quot;&lt;Motion&gt;&quot;, move)<br>&lt;Motion event x=23 y=9&gt;<br>&lt;Motion event x=24 y=9&gt;</pre><p>Every time mouse moves, event is triggered and function <em>move </em>called.</p><p>We can detect when the mouse pointer enters the widget and leave it using events called <em>enter</em> and <em>leave.</em> Let us add some code that will print message <em>Entered/Left</em> along with event information:</p><pre>def enter(event)<br>    print(&quot;Entered:&quot;, event)<br>def leave(event):<br>    print(&quot;Left:&quot;, event)<br>label.bind(&quot;&lt;Enter&gt;&quot;, enter)<br>label.bind(&quot;&lt;Leave&gt;&quot;, leave)</pre><p>Now when we place pointer over the widget,slowly placing it inside borders, so not many <em>Motion </em>events will be triggered, we will get this:</p><pre>Entered: &lt;Enter event focus=False x=48 y=20&gt;<br>…<br>&lt;Motion event x=47 y=14&gt;<br>Left: &lt;Leave event focus=False x=50 y=18&gt;</pre><p>Mouse bindings make Tkinter widgets much more interactive by allowing them to respond directly to pointer movement and button actions. Together with the event object, they provide a simple way to determine what happened and where it happened,and act appropriately.</p><p><strong>If you found this article helpful, consider supporting my work with a </strong><a href="https://ko-fi.com/jasenko/donate"><strong>small donation</strong></a><strong> on Ko-fi:<br></strong><a href="https://ko-fi.com/jasenko/donate"><strong>https://ko-fi.com/jasenko/donat</strong></a>e</p><p>If you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=450161aefacd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Subnet Port Scanner in Python Using the socket and ipaddress Modules]]></title>
            <link>https://medium.com/@krejjas/subnet-port-scanner-in-python-using-the-socket-and-ipaddress-modules-5b63b9bd936c?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b63b9bd936c</guid>
            <category><![CDATA[ssh]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[port-scanner]]></category>
            <category><![CDATA[sockets]]></category>
            <category><![CDATA[ip-address]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Thu, 27 Aug 2026 07:41:47 GMT</pubDate>
            <atom:updated>2026-08-27T07:41:47.406Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*-4EREcy5n0BrN7fwzKruUw.png" /></figure><p>When you manage or troubleshoot a network, you may need to determine which hosts in a subnet are listening on a particular TCP port. For example, checking port 22 can help identify systems where the SSH service is available.</p><p>Usually, when I wanted to do this in Linux shell, I used to create a file containing IP addresses, read them one by one, and use <em>nc(netcat)</em> command to check for open port.</p><p>In Python, things become easier and more powerful at the same time. You don’t need to specify the addresses in the subnet manually. There is a built-in module, <em>ipaddress</em>, which provides the ip<em>_network()</em> function.</p><p>This function takes a subnet as an argument and returns a network object representing that subnet:</p><pre>import ipaddress<br>subnet = ipaddress.ip_network(&quot;10.10.10.0/28&quot;)<br>print(type(subnet))<br>&lt;class &#39;ipaddress.IPv4Network&#39;&gt;</pre><p>Now we have this object, but what can we do with it. Can we iterate over it? Let us try:</p><pre>for ip in subnet:<br>    print(ip)<br>10.10.10.0<br>…<br>10.10.10.15</pre><p>You can see that we only have to use a for loop to get all the addresses and process them as we like.</p><p>But that is not all — we can also easily obtain different network information, such as the network address, broadcast address, netmask in <em>x.y.z.w </em>format, and the total number of addresses. And, as the cherry on top, we can get a list of all usable host addresses.</p><p>Just look at this code:</p><pre>print(subnet.network_address)<br>10.10.10.0<br>print(subnet.num_addresses)<br>16<br>print(subnet.broadcast_address)<br>10.10.10.15<br>print(subnet.hosts())<br>&lt;generator object _BaseNetwork.hosts at 0x000001FE9A102CE0&gt;</pre><p>When we check for open ports on subnet IPs, we will exclude network address and the broadcast address, so <em>hosts()</em> will be useful.</p><pre>hosts = subnet.hosts()</pre><p>Now, we can iterate through useful IPs in the subnet, but how can we check if a port is open? I will talk specifically about TCP port, because UDP is different- it doesn’t create a connection, and might not send response, even if it is open.</p><p>For each individual IP address, we can test whether a TCP port is open by creating a socket and trying to establish a connection to that IP address and the desired port. I will use port 22, which is the default port for the SSH protocol and is commonly used for encrypted remote connections.</p><p>We need to import <em>socket </em>module:</p><pre>import socket</pre><p><em>socket </em>module has function of the same name, <em>socket,</em> that creates a <em>client socket-</em> an IP address/port pair that will connect to remote IP/port pair.</p><pre>client = socket.socket()</pre><p>We called it <em>client </em>because it will try to connect on port 22 to IPs from the subnet. Now the configuration part- we can try to connect, but we don’t want the client trying to connect for too long-it will wait for long time, until something like operating system decides to abort the connection. We can fortunately set this timeout to be something reasonable, like 1 second. If there is a response, it will usually take much less time. This is configured with:</p><pre>client.settimeout(1)</pre><p>Now we can try to connect:</p><pre>result = sock.connect_ex((ip, port))</pre><p>We are not using the more common <em>connect()</em> function (discussed in one of my previous articles), but its close cousin, <em>connect_ex().</em></p><p>When the connection fails, <em>connect()</em> raises an exception, while <em>connect_ex()</em> returns 0 on success and a non-zero integer error code if the connection fails for any reason. We will not inspect these error codes; we will simply react when 0 (success) is returned. This is a full <em>for</em> loop:</p><pre>for ip in subnet:<br>    client = socket.socket()<br>    client.settimeout(1)<br>    result = client.connect_ex((str(ip), port))<br>    if result == 0:<br>        print(f&quot;Port {port} on {ip} is open&quot;)</pre><p>There are some important details here: when passing an argument to <em>connect_ex()</em> method, you need to take care that it is a tuple- so, notice the extra pair of parenthesis. Also, in this tuple, you can not pass and <em>ip</em> directly, because it is an <em>IPv4Address</em> type of object, and first element should be string.</p><pre>print(type(ip))<br>&lt;class &#39;ipaddress.IPv4Address&#39;&gt;</pre><p>This is simple to resolve, because we can use <em>str</em> function to convert it to string. And that is exactly what we did.</p><p>Let us run the program and suppose that we have two open <em>SSH</em> ports on our hypothetical 10.10.10.0/28 network. We will get the following output:</p><pre>Port 22 on 10.10.10.2 is open<br>Port 22 on 10.10.10.4 is open</pre><p>You have seen a practical use of Python <em>socket</em> and <em>ipaddress</em> modules: scanning the IP addresses in a subnet and checking whether a particular TCP port is open. The <em>ipaddress</em> module makes it easy to iterate through IPv4 network subnet addresses ,and <em>socket</em> provides the way to attempt connections to each IP. Using <em>connect_ex()</em>allows connection results to be handled through return codes rather than exceptions, like <em>connect()</em> does.</p><p>This is only a small subset of what these two modules can do. The <em>socket</em> module supports many more features, including TCP and UDP communication, creating client and server applications, hostname and address resolution, service name lookups and so on.</p><p><em>ipaddress</em> has features for working with IP addresses, networks, subnetting, address validation, network membership, just to name most important ones.</p><p>The subnet port scanner presented here is just a simple introduction to combining these two powerful built-in modules rather than as a comprehensive demonstration of their capabilities, which are discussed in my other articles.</p><p><strong>If you found this article helpful, consider supporting my work with a </strong><a href="https://ko-fi.com/jasenko/donate"><strong>small donation</strong></a><strong> on Ko-fi:<br></strong><a href="https://ko-fi.com/jasenko/donate"><strong>https://ko-fi.com/jasenko/donat</strong></a>e</p><p>If you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b63b9bd936c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Python sqlite3: From execute() to fetchall()]]></title>
            <link>https://medium.com/@krejjas/python-sqlite3-from-execute-to-fetchall-34a2dc73c6db?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/34a2dc73c6db</guid>
            <category><![CDATA[sqlite]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[db-api-2]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[sqlite3]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Tue, 25 Aug 2026 09:46:50 GMT</pubDate>
            <atom:updated>2026-08-25T09:46:50.127Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*--LCuqP-RRuLIjIxTiAYOQ.png" /></figure><p>Python makes working with SQLite straightforward through the built-in sqlite3 module. SQLite does not require a separate database server, and an entire database can be stored in a single file, which makes it especially convenient for learning, small applications, testing, and local data storage.</p><p>In this article, we will focus on the Python-side workflow of working with SQLite: creating a connection, creating and using a cursor, executing SQL statements with <em>execute()</em>,<em> executemany()</em>, and <em>executescript()</em>, and retrieving query results with <em>fetchone()</em>, <em>fetchmany()</em>, and <em>fetchall</em>.</p><p>An important point is that Python’s <em>sqlite3</em> module is compatible with the <em>Python Database API Specification v2.0</em>,(DB-API 2.0, defined in PEP 249).Many concepts you learn here — such as connections an cursors and their methods — are part of a common database programming interface used by many Python database drivers.</p><p>To work with the database, we use <em>connection </em>object, but not directly. We need to create something called<em> cursor</em> object from the database. It is a kind of handler, just like we create a file handler in Python, and pass commands to handler, not to file directly. You can say, there are multiple layers: database file, connection, cursor.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/129/1*ryvqWfRHPh0aVGf9Norz6A.png" /></figure><p>Cursor is the agent we are communicating with- giving it commands and receiving results from operation. Here, we will create a table, with <em>id, name</em> and <em>age</em> columns, a typical SQL query, with additional options to make <em>id</em> column primary key and to autoincrement it, if omitted. We use <em>execute() </em>method of cursor object to execute query, either directly or from a string variable. At the end, we need to use the same object’s <em>commit()</em> method, which acts as an <em>Apply</em> button — nothing is really executed until we commit it.</p><pre>import sqlite3<br>conn = sqlite3.connect(&quot;users.db&quot;)<br>cur = conn.cursor()<br>cur.execute(&quot;&quot;&quot;<br>CREATE TABLE IF NOT EXISTS users (<br>    id INTEGER PRIMARY KEY AUTOINCREMENT,<br>    name TEXT NOT NULL,<br>    age INTEGER NOT NULL<br>)<br>&quot;&quot;&quot;)<br>conn.commit()</pre><p>Let us add some data to the table, so we can work with it:</p><pre>query = &quot;INSERT INTO users values  (1, &#39;Alice&#39;, 25)&quot;<br>cur.execute(query)</pre><p><em>execute() </em>has one caveat: it can execute only a single SQL query. So what do we do if we need to execute multiple INSERT statements? Do we need to call<em> execute() </em>every single time? Fortunately, we have method called<em> executescript().</em> This method accepts a string that may contain multiple SQL statements, separated by a semicolon.</p><pre>query = &#39;&#39;&#39;INSERT INTO users values  (2, &#39;Tanya&#39;, 30);<br>           INSERT INTO users values  (3, &#39;Peter&#39;, 33);&#39;&#39;&#39;<br>cur.executescript(query)<br>There is also a method named executemany(). You may think that it means “execute many lines,” but that is not the case. The name is slightly misleading. What it actually does is execute the same query multiple times, using different values</pre><p>There is also a method named <em>executemany()</em>. You may think that it means <em>“execute many lines,”</em> but that is not the case. The name is slightly misleading. What it actually does is execute the same query multiple times, using different values taken from a list or another sequence.</p><pre>query = &quot;INSERT INTO users VALUES (?, ?, ?)&quot;<br>users = [<br>    (4, &quot;Sara&quot;, 28),<br>    (5, &quot;Mike&quot;, 35)<br>]<br><br>cur.executemany(query, users)</pre><p>Do you see the pattern? It is as if we started a for loop and, in each iteration, passed a tuple from the users list.</p><p>At this point, if you run the program many times, you might have existing database, and inserting data with the same <em>id</em> will yield an error. Clearing the database is as simple as deleting a <em>users.db</em> file from the file manager in PyCharm or even programmatically with the <em>os </em>module. You might want to delete the file after running program so you don’t try inserting duplicate data.</p><pre>import os<br>os.remove(&quot;users.db&quot;)</pre><p>These are different ways we can execute SQL commands. But when we read data, with SELECT, how do we obtain results?</p><p>The most common SQL SELECT command is as follows, returning all data from the table.</p><pre>cur.execute(&quot;SELECT * FROM users&quot;)</pre><p>Don’t forget to put <em>conn.commit()</em> after inserts, and not <em>cur.commit().</em> Interestingly, <em>cur</em> contains results as well, and we don’t need <em>commit()</em> after SELECT.</p><p>We can get all rows of select with<em> fetchall() </em>method:</p><pre>results = cur.fetchall()</pre><p><em>rows </em>is a regular list, not some exotic iterable as you might have expected. We can iterate over it to see its values.</p><pre>for result in results:<br>    print(result)<br>(1, &#39;Alice&#39;, 25)<br>(2, &#39;Tanya&#39;, 30)<br>(3, &#39;Peter&#39;, 33)<br>(4, &#39;Sara&#39;, 28)<br>(5, &#39;Mike&#39;, 35)</pre><p>Cursor is similar to iterator, because it knows where its position is. Since we fetched every row, calling <em>fetchall()</em> again will return an empty list.</p><pre>results = cur.fetchall()<br>print(results)<br>[]</pre><p>To fetch the rows again into cursor, execute the SELECT again:</p><pre>cur.execute(&quot;SELECT * FROM users&quot;)</pre><p>Before we move one, let me show you a hidden ability of cursor-you don’t even need to use <em>fetchall()</em> method, <em>cur </em>itself can be iterated over, row by row. Change the previous line:</p><pre>crows = cur.execute(&quot;SELECT * FROM users&quot;)</pre><p>Now, you can use <em>for </em>loop on this list directly:</p><pre>for row in crows:<br>    print(row)<br>(1, &#39;Alice&#39;, 25)<br>(2, &#39;Tanya&#39;, 30)<br>…</pre><p>So why use <em>fetchall(),</em> when we can directly iterate over rows? I will reveal it after we learn yet another way to read results.</p><p>There is another method, called <em>fetchone(),</em> which will do exactly what it says: fetch one row from the result.</p><pre>execute(&quot;SELECT * FROM users&quot;)<br>row = cur.fetchone()</pre><p><em>row</em> now contains, you guessed it, the first database row:</p><pre>print(row)<br>(1, &#39;Alice&#39;, 25)</pre><p>If we run it again, it will fetch the second row, and so on. When it reaches the end, it returns <em>None.</em></p><p>If you think these are all methods for retrieving rows from the result list, you are wrong. There is another one, called <em>fetchmany().</em> It returns a specified number of rows, starting from the cursor current position. And in our case, cursor position is at the second row(still not returned yet).</p><pre>rows = cur.fetchmany(2)<br>for row in rows:<br>    print(row) <br>(2, &#39;Tanya&#39;, 30)<br>(3, &#39;Peter&#39;, 33)</pre><p>If we don’t specify the number it will default to a variable <em>cur.arraysize,</em> which is usually 1, and can be changed.</p><p>And at the end, let me tell you why use <em>fetchall(). </em>At this point, we have cursor at position 4. If we execute a <em>fetchall(),</em> it will return all remaining rows, from the current cursor position to the end.</p><pre>rows = cur.fetchall()<br>for row in rows:<br>    print(row)<br>(4, &#39;Sara&#39;, 28)<br>(5, &#39;Mike&#39;, 35)</pre><p>After you finish, be kind enough to close the connection:</p><pre>conn.close()</pre><p>To conclude: SQLite’s <em>execute(),</em> <em>executemany(),</em> and <em>executescript()</em> methods give you flexible ways to run SQL statements, while <em>fetchone(),</em> <em>fetchmany(),</em> and <em>fetchall()</em> let you retrieve a single row, a batch of rows, or the entire remaining result set. Together, these methods provide the core workflow for executing queries and reading results through SQLite’s cursor interface, which largely follows Python’s DB-API 2.0 specification.</p><p><strong>If you found this article helpful, consider supporting my work with a </strong><a href="https://ko-fi.com/jasenko/donate"><strong>small donation</strong></a><strong> on Ko-fi:<br></strong><a href="https://ko-fi.com/jasenko/donate"><strong>https://ko-fi.com/jasenko/donat</strong></a>e</p><p>If you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34a2dc73c6db" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Message Boxes in Tkinter]]></title>
            <link>https://medium.com/@krejjas/working-with-message-boxes-in-tkinter-0d8d5d1ba285?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d8d5d1ba285</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[python-programming]]></category>
            <category><![CDATA[messagebox]]></category>
            <category><![CDATA[tkinter]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Mon, 24 Aug 2026 08:43:00 GMT</pubDate>
            <atom:updated>2026-08-24T08:43:00.359Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Tkinter</em> has many different widgets, and <em>messagebox</em> provides a collection of ready-made dialog boxes. Remember those small pop-up windows that ask you to confirm or reject something, or simply display a warning or an error? Those are message boxes. In fact, <em>messagebox</em> is a module containing several different types of message boxes.</p><p>Importing it is easy and is done separately from the usual <em>Tkinter</em> import. Then, we create the usual main <em>Tkinter</em> window, commonly stored in a variable called <em>root</em>.</p><pre>import tkinter as tk<br>from tkinter import messagebox<br>root = tk.Tk()</pre><p>Let us start with the most simple message box, the one that is called <em>showinfo.</em> It doesn’t do much- just shows a message, and it can accept another argument, a title of this window, which is the first argument.</p><pre>messagebox.showinfo(&quot;Hello&quot;,&quot;Hello, World!&quot;)<br>root.mainloop()</pre><p>Don’t forget <em>root.mainloop,</em> which acts as a trigger to start the <em>tkinter </em>application.</p><p>After we start the program, we will get a popup:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/266/1*t-GAS1tWexzRBW0kjXTsyg.png" /></figure><p>Clicking <em>OK</em> will close it and return the execution to main application.</p><p>Another message box, quite similar to this one, is <em>showwarning.</em> It accepts the arguments, title and message, but it has different purpose-it is intended to warn about something.</p><pre>messagebox.showwarning(&quot;Caution&quot;, &quot;Take care!&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*XmUr4BPBsXgkyxluOHZR0w.png" /></figure><p>You can see that the icon has changed to yellow triangle with a question mark.</p><p>Going even further, we can use the <em>showerror</em> message box. The icon will now change to red circle with an x in the middle.</p><pre>messagebox.showerror(&quot;Error&quot;, &quot;Critical situation!!!&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/237/1*GxQCh8sUdfrCd34pPz33Uw.png" /></figure><p>All these boxes were informational, differing only in severity of the message(informational, warning, error). There is a messagebox that actually requires and uses the user input. Meet <em>askyesno.</em></p><pre>messagebox.askyesno(&quot;Confirmation&quot;, &quot;Are you sure?&quot;)</pre><p>You will get a message box where you can answer either <em>Yes</em> or <em>No.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*AD3ijUBKYb0YpbYeApefqA.png" /></figure><p>When you answer, the box closes. How do we use this user input? The answer that is selected by the user is the return value of this messagebox, and it can be stored in a variable, which we can print, or use some other way.</p><pre>sure = messagebox.askyesno(&quot;Confirmation&quot;, &quot;Are you sure?&quot;)<br>print(&quot;Sure:&quot;, sure)</pre><p>If we click <em>No,</em> we will get this in the terminal window.</p><pre>Sure: False</pre><p>Very similar to <em>askyesno</em> is <em>askokcancel,</em> only instead of <em>Yes,</em> there is <em>Ok,</em> and instead of <em>No,</em> there is <em>Cancel</em> shown. <em>Ok </em>returns <em>True,</em> <em>Cancel</em> returns <em>False.</em></p><pre>proceed = messagebox.askokcancel(&quot;Proceed&quot;, &quot;Proceed or cancel?&quot;)<br>print(&quot;Proceed:&quot;, proceed)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/323/1*gf4jRSl6gne_vXQR_YE1Tw.png" /></figure><p>Until now, we have allowed user to chose between two choice, so return value was either <em>True</em> or <em>False.</em></p><p>Imagine closing a file that has unsaved changes- you may ask the user to save them,. Loose them or cancel the closing of the file. So, there are three changes. This is the use case for <em>askyesnocance </em>message box.</p><pre>save = messagebox.askyesnocancel(&quot;Save&quot;, &quot;Save/not save/cancel?&quot;)<br>print(&quot;Save:&quot;, save)</pre><p>You may ask: if <em>yes</em> returns<em> True,</em> and <em>no</em> <em>Fasle,</em> what happens when the user clicks <em>Cancel? </em>Let’s try:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/453/1*Sgj6F3zLfiZ091WjVLpUeg.png" /></figure><pre>Save: None</pre><p>The answer is: <em>None.</em></p><p>There is one more <em>messagebox</em> function that is mostly deprecated but still useful to recognize: <em>askquestion</em>. It has the same purpose as <em>askyesno</em>, but instead of returning Boolean values, it returns the strings “yes” and “no”.</p><p>These are the basic <em>Tkinter</em> message boxes. They are very useful for user interaction because they provide simple pop-up dialogs that are separate from the main application window.</p><p><strong>If you found this article helpful, consider supporting my work with a </strong><a href="https://ko-fi.com/jasenko/donate"><strong>small donation</strong></a><strong> on Ko-fi:<br></strong><a href="https://ko-fi.com/jasenko/donate"><strong>https://ko-fi.com/jasenko/donat</strong></a>e</p><p>If you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d8d5d1ba285" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Static Methods in Python]]></title>
            <link>https://medium.com/@krejjas/static-methods-in-python-36d5df444459?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/36d5df444459</guid>
            <category><![CDATA[static-methods]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[python-programming]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Fri, 21 Aug 2026 06:26:48 GMT</pubDate>
            <atom:updated>2026-08-21T06:26:48.323Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FRj2up8Q5-RG82p6g_coXA.png" /></figure><p>Python classes can contain methods, that is, functions that belong to the class. Technically, these are like variables, only their type is <em>function.</em> Usually, we start with normal or instance methods, ones that require <em>self</em> as the first parameter. <em>self</em> references the instance of the class, since we can’t refer to an instance by name-instances don’t have names. There can be other parameters as well, but <em>self</em> is obligatory, so we can reference an instance within that method with <em>self</em></p><p>Then, there are class methods, preceded by <em>@classmethod</em>. Instead of <em>self,</em> first parameter, usually called <em>cls,</em> is a class where it is defined. It can access class attributes, but not instance ones.</p><p>But what if we don’t want to do anything with an instance or a class? We want only a method that for example, convert miles from kilometers, in a class <em>Car.</em> Meet the <em>static method.</em> It is a method that has <em>@staticmethod</em> above its definition, like this:</p><pre>class Car:<br>    @staticmethod<br>    def conversion_miles_kms (miles):<br>        return miles *  1.60934</pre><p>When we define method as static, we don’t need to pass <em>self</em> or <em>cls-</em> in fact, we even can’t. We can only pass optional arguments(in our case, mileage). Let me ask you a question- what will happen if we modify the method to look like this:</p><pre>@staticmethod<br>def conversion_miles_kms (self)<br> pass</pre><p>If you expect an error, or that you can still use <em>self, </em>you are wrong. When we define method as static, <em>self</em> is a regular parameter, not an instance of a class as you might expect. Remember, <em>self</em> and <em>cls</em> are only conventional names, and in normal methods and class methods, you can use any name for that first parameter.</p><p>Revert to the original method definition in your code.</p><p>When we create a class, we usuallyuse it to create an instance. So let us create one:</p><pre>renault_megane = Car()</pre><p>We can call a static method via this instance:</p><pre>print(renault_megane.conversion_miles_kms(100))<br>80.467</pre><p>This works fine- but we can also use static method without creating an instance, or, instantiating the class, just like we can use <em>@classmethod</em> methods without creating an instance.</p><pre>print(Car.conversion_miles_kms (200))<br>321.868</pre><p>Why would we use static methods at all? Not having access to instance or class details is not an advantage. But, for using calculation that requires only arguments explicitly passed to it, or even no arguments at all, without without class or instance attributes is sometimes enough.</p><p>To summarize: you can use a static method to logically group functions as methods within a class. Although you could use a standalone function such as <em>conversion_miles_kms,</em> isn’t it nicer to place it in a <em>Car</em> class? Then you could also add methods such as <em>hp_to_kw,</em> which converts horsepower to kilowatts, or <em>cost_calculator,</em> which takes mileage, fuel cost, and average fuel consumption per 100 kilometers as parameters. These are just examples. You will surely come up with others that are useful for your own projects.</p><p>Once you define a static method, you can call static methods not only from outside the class, but also from within other methods that belong to the class:</p><pre>    def mileage_in_km(self):<br>return Car.conversion_miles_kms(self.mileage)</pre><p>Even if you don’t use <em>@staticmethod</em> yourself, you need to know them, because a lot of code you encounter is using it these days.</p><p><strong>If you found this article helpful, consider supporting my work with a small donation on Ko-fi:<br>https://ko-fi.com/jasenko/donate</strong></p><p>If you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=36d5df444459" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTTP Status codes]]></title>
            <link>https://medium.com/@krejjas/http-status-codes-2de696550370?source=rss-d0a1eab05ce8------2</link>
            <guid isPermaLink="false">https://medium.com/p/2de696550370</guid>
            <category><![CDATA[internet]]></category>
            <category><![CDATA[www]]></category>
            <category><![CDATA[https]]></category>
            <dc:creator><![CDATA[Jasenko Krejić]]></dc:creator>
            <pubDate>Wed, 19 Aug 2026 09:01:15 GMT</pubDate>
            <atom:updated>2026-08-19T09:02:34.933Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/975/1*v5_h3S4r3COF-Qm_Q-jbHw.png" /></figure><p>World Wide Web or the Internet as we know it evolved with the HTTP protocol. Short for Hypertext Transfer Protocol, it is the way for a client (like Web browser) to communicate with web server (a Flask or Apache server). As with all client server communication, client initiates the communication by sending a request to the server. Server returns a response. In the simplest form, client sends a request to the server for a web page, like <a href="http://www.python.org,and/"><em>www.python.org,</em>and</a> server returns a web page. That it the simplified version, because today there are a lot more moving parts involved in this communication. I will stick to this example.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/279/1*ou7-Jof8KzU0NrIi4vj4ug.png" /></figure><p>When a request is sent, server receives it and responds appropriately. Among other things, like headers and body, there is a code that server uses to indicate what happens with the request. This code is called a status code, and it is a three-digit number. There are five possible HTTP response code groups- these are logically grouped codes; each group starts with the same first digit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/401/1*1mG-lHaX_pMXitTHClgPcg.png" /></figure><p>Informational status codes are 1xx. It just informs you that the request has been received. It is not part of standard exchange of requests and responses. An example is <em>100 Continue, </em>which server sends back to the client, saying that client may continue with action like uploading a file, or <em>120 Processing, </em>used when the server has successfully received the request, but it takes time to process it.</p><p>Then, we have 2xx codes. These codes are a success code, but with slightly different information attached to them. You will see mostly <em>200 OK</em> status code, that signifies successful return of requested resource. If a result of request is that something is created, we have a <em>201 Created</em> status code, and if server receives the request, but will take some time to finish processing it, it will send <em>202</em> <em>Accepted.</em> If request succeeds, but no response body is returned, status code <em>204 No Content </em>appears.</p><p>3xx status codes are returned when additional action is required to complete the request, most commonly because the requested resource is located elsewhere or because a cached copy can be used. For example, some images may have been relocated to another server. When <em>301 Moved Permanently</em> is returned, the new location is also provided in the response, so the browser automatically sends a request to the new location. <em>302 Found</em> is similar to 301, but indicates that the relocation is only temporary. The <em>304 Not Modified</em> status code can be returned when the client has a cached copy of a resource and makes a conditional request to check whether the resource has changed. If the resource, for example an image, has not changed, the server returns 304, so the client does not have to download the resource again and can use its cached copy.</p><p>4xx status codes are returned when the server cannot complete the request because there is a problem on the client side. For example, the client may send an invalid request, request a resource that does not exist, or try to access a resource that it doesn’t have permissions for. <em>400 Bad Request</em> signifies the server cannot process the request because it is invalid for some reason. <em>401 Unauthorized </em>indicates that authentication is required or provided credentials are not valid. It is about authentication, and the name is misleading(<em>unauthorized, </em>instead of <em>unauthenticated</em>). <em>403 Forbidden</em> means that the client has authenticated successfully, but does not have permission to access the requested resource(authorization). The infamous <em>404 Not Found</em> status code is returned when the requested resource cannot be found on the server.</p><p>5xx status codes are returned when the server cannot complete the request because there is a problem on the server side. For example, the server may encounter an unexpected error, be temporarily overloaded, or fail to receive a proper response from another server. <em>500 Internal Server Error</em> indicates that the server encountered a problem, usually with misconfiguration.<em>502 Bad Gateway </em>is returned when we access a proxy server, a public-facing that asks for a backend server for real data, and that backend server is unavailable. <em>503 Service Unavailable</em> means that the server is temporarily unable to process requests, for example because it is undergoing maintenance. The <em>504 Gateway Timeout</em> status code is returned when a proxy waits for a response from that another server but there is a timeout.</p><p>There are some more status codes, but these are less likely to appear and easy to find if you encounter them.</p><p>If you want to see status codes when you visit a web site, here is a quick way to do it.</p><p>For example, in Google Chrome browser, open the <em>python.org page</em>. Then press F12 to start developer tools. These built-in tools can help you to get a low-lever insight into what is really going on when you browse a web page. It is not a single request, but a multiple requests, with multiple status codes, even different HTTP versions. Choose <em>Network</em> tab and reload page(F6) to see what requests and responses are present. You may be surprised to see how many requests and responses are hidden in one visit to a web page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/748/1*q3e-ojiTGJq-QZcequ7kVQ.png" /></figure><p>You may browse some other sites, and try to find some of the status codes we discussed in this article.</p><p><strong>If you found this article helpful, consider supporting my work with a small donation on Ko-fi:<br>https://ko-fi.com/jasenko/donate</strong></p><p>If you are learning Python, and want to follow the PCEP Python exam syllabus, check my newest Udemy Course, it is a video tutorial packed with hands-on example, quizzes, coding exercises and two full mock exams:</p><p><a href="https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/?srsltid=AfmBOooW9UzR6RfwGL6DiHkdW1jllj5_4HbyqtKV8NlZLivT-YjffizL&amp;couponCode=24T5MT071025">https://www.udemy.com/course/pass-python-pcep-30-0x-video-lessons-and-mock-tests-2025/</a></p><p>If you want to learn more about AWS Lightsail service, check my course on Udemy on AWS Lightsail.</p><p><a href="https://www.udemy.com/course/aws-lighsail-a-different-perspective">https://www.udemy.com/course/aws-lighsail-a-different-perspective</a></p><p>Also, if you want to prepare for the basic AWS Certified Cloud Practitioner exam, check another one of my courses, also on Udemy:</p><p><a href="https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course">https://www.udemy.com/course/aws-certified-cloud-practitioner-crash-course</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2de696550370" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>