Spinbox in Tk (tkinter)

The ttk.Spinbox widget is similar to a textbox, but it also incorporates two buttons to increase or decrease its numerical content. Although this is its main use (as a container for numeric data), it can also display non-numeric values, like a dropdown list. We'll see their differences in the last section.

In order to present all the functionalities of a spinbox, we will develop a virtual thermostat like the following:

/images/spinbox-in-tk-tkinter/thermostat-tkinter.gif

Read more…

Iterators, Iterables and the next() Function

If you have heard about iterators or iterable objects, which is quite common in Python, or read some code that makes use of the next() or iter() functions, and if you are interested in knowing what all that is about, this is the article for you. Iterators and iterable objects (or just iterables) are used all the time, though often indirectly, and form the basis of the for loop and more complex functionality like generators (yield) and asynchronous tasks (async).

Read more…

Contact Form With reCAPTCHA for Shared Hosting

/images/contact-form-with-recaptcha-for-shared-hosting/contact-form-with-recaptcha-for-shared-hosting.gif

If you have a classic, static HTML site in a shared hosting service and you want to let your users reach you with a simple contact form, there is no need to install WordPress! Just upload the following Python CGI script protected by reCAPTCHA v2 into your public_html/ directory (or wherever you store your HTML files) as contact.py.

Read more…

Shutdown, Reboot and Log Off on Windows and Linux

There is no standard function to shutdown, reboot or log the user off on both Windows and Linux systems, so you will need to use ad hoc code for each operating system. However, you might create a function that executes the proper code based on the value of the standard os.name string if you are working on a cross-platform project.

Read more…