Styling Widgets in Tk (tkinter)

You already have a desktop application written in Python with Tk, and now you want to make some changes to the appearance of the UI (buttons, labels, text boxes, etc.) By default, widgets in a tkinter application have a certain appearance, which in most cases is quite acceptable as it conforms to operating system standards. However, you have the possibility of altering the default appearance of any widget (e.g., changing the text color of a button from black to red). This can be done in two different ways.

Read more…

Creating and Setting Up a Django Project

Developing a new website in Django requires a series of initial steps that can be somewhat tedious and confusing when getting started with the framework: creating the project, setting up an application, configuring the URLs, etc. Here is a quick and easy to follow guide that can be used as reference every time you need to start a new project.

Read more…

Reproducing SQL Injection in sqlite3 and PyMySQL

SQL injection is a security vulnerability that allows an unauthorized user to execute SQL queries against a database. It can be exploited in any type of application (console, web, desktop, mobile). An application might be vulnerable to SQL injection when allowing the user to enter some data that is later included in a database query. In this post you will learn how to create and exploit vulnerable code in Python, using SQLite and MySQL as example databases. If you want to keep your Python application secure, you need to know how vulnerabilities arise!

Read more…

Scrollbar in Tk (tkinter)

The scrollbar is a Tk widget that allows you to modify the visible area (called viewport) of other widgets. A scrollbar can be vertical or horizontal, and is typically attached to widgets that display multiple elements, lines, or columns, such as listboxes (tk.Listbox), tree views (ttk.Treeview) or multi-line textboxes (tk.Text). In this post you will learn how to create and configure scrollbars.

/images/scrollbar-in-tk-tkinter/listbox-with-scrollbar.gif

Read more…

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…