Posts

How to install PyQt5 and Qt Designer on Ubuntu

Image
PyQt is the binding of Qt for Python. It allows us to use the graphic framework Qt to create Graphic User Interfaces for our Python programs. Qt is not only a very complete library for GUI development, one of its advantages over other GUI libraries for Python like Tkinter, is its graphic designer: Qt Designer , that we can use to draw graphic interfaces for our programs by dragging and dropping widgets in a window with no need to code, simplifying the process of designing the GUI. Installing Qt and Qt Designer To get Qt Creator and Qt Designer in your system you need to type the following commands in the terminal: sudo apt install build-essential sudo apt install qtcreator sudo apt install qt5-default The build-essential includes all the tools needed to create packages for Debian and Ubuntu, while qtcreator will install Qt Creator, the IDE used to build Qt Apps. qt5-default will allow us to use Qt5 as the default version of Qt in Qt Creator. Installing PyQt5 T

Dice grid from a photo with Python (V) - Creation of a stand-alone executable

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Creation of the stand-alone executable Introduction Up to this point, we've designed the program and created the modules and the GUI coding with Python. We could now say that the program is complete! But we can still work on one last thing: The creation of a stand-alone executable that will help us to distribute our program, as it will be able to be run on any machine even without a Python interpreter installed. For this, we'll use Pyinstaller . With pyinstaller you can create an executable file for your operative system (i.e. you can not create an EXE for Windows running pyinstaller on Ubuntu, to do that you'd need to run it on Windows).  Downloading Pyinstaller Pyinstaller can be added to your machine through PIP with the following command: pip install pyinstaller

Dice grid from a photo with Python (IV) – Designing the GUI with Tkinter

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Documentation and creation of the stand-alone executable Introduction So far, we've been able to successfully create a dice grid from any picture using PIL and Python. However, running the script and modify the path to the picture every time we want to make a grid becomes tedious very quickly and its not the most friendly way to do the things. We can significantly enhance the user-experience through a GUI that will let us visualize a preview of the final result and browse through the folders of our system to find the pictures we want to send to the script. In this post, I'll show you how to design a GUI with Tkinter , and in the next post, I'll show you how to create an stand-alone executable that you will be able to distribute and run without having Python installed in your c

Project: Create a dice grid from a photo with Python and PIL

Image
Some days ago a popular post on Reddit showed how an user of the platform made a portrait from a photo using dice; an impressive and relatively easy replicable task that would be an excellent project for beginners in Python :) That's why I've decided to code a program to create a grid of dice from a photo using Python and share the process of coding from start to finish in this blog in a series of posts. The skills developed in this project are: Real-life problems analysis Use and creation of modules in Python Use of the Python Image Library (Pillow) Use of Tkinter to create Graphic User Interfaces Use of docstrings to document the code Convert of Python Applications to Stand-Alone Windows executables  And below you can find the links to the posts: The logic behind the program Creation of the dice Create a grid of dice from a photo Design of the GUI Make a stand-alone executable Github: https://github.com/Nxz02/Pic2DicePy

Dice grid from a photo with Python (III) – Creating the resulting picture

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Document and creation of the stand-alone executable Introduction In the first post of this project I mentioned the steps to create a dicing grid parting from a picture: Divide the picture into subsets Analyze each subset and replace it with the correspondent die based on its brightness I already defined the functions to draw the dice, so in this post I'm going to continue with the functions needed to transform the picture into a grid of dice, basically finishing the main purpose of this project. The steps to code the dicing grid are a bit different than the mentioned before, being like this: Get the constant values using the formula mentioned in the first post Validate or resize the size of the picture Divide the picture into subsets Analyze each subset and replace it with th

Dice grid from a photo with Python (II) – Drawing the dice

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Drawing the dice Create a grid of dice from a photo Design of the GUI Document and creation of the stand-alone executable Introduction In the previous post we analyzed all the steps to create a dicing grid from a picture in theory, but no code was written. In this post, I will show you how to draw dice with Pillow and its methods. In this post, we will see: How to install Pillow as a Python module How to import and use the methods in PIL.Image and PIL.ImageDraw in our code How to divide our code into functions Use of arguments and keyword arguments Installation of Pillow Pillow is a library that adds support for manipulation of images in Python. Pillow is a fork of PIL , appearing after the later stopped being updated in 2009. You can install Pillow through PIP on Windows, Mac, and Linux with the command: pip install Pillow Installing Pillow

Dice grid from a photo with Python (I) – Logic behind the program

Image
This post is part of the Project: Create a grid of dice from a photo with Python and PIL The logic behind the program Creation of the dice Create a grid of dice from a photo Design of the GUI Document and creation of the stand-alone executable Introduction Before we code the program, it is necessary to have a general idea about how we will solve the problem that surrounds us. Here, we want to know how can we create a grid of dice parting from a picture, and what must we do to put the correct dice in each part of the picture in such a way that the result resembles the original picture. Note: In this post, I will only show the logic behind the program and therefore no coding will be done. In this post, we will analyze: How to draw the dice How to divide the picture into subsets How to decide which die paste in each part of the picture Thinking of a template for the die We are going for the simplest approach to draw the dice: 1 dot per pixel. As the die is a cube