Creating graphical user interfaces (GUI) can be difficult. There are many different Python GUI toolkits to choose from. The top three that you are likely to see mentioned the most often are Tkinter, wxPython and PyQt (or PySide2). However there is a newer toolkit called PySimpleGUI that aims to make creating GUIs easier.
The way that PySimpleGUI gets its power is by being an abstraction layer on top of Tkinter, wxPython and PyQt. You can kind of think of PySimpleGUI as a wrapper. The developers behind PySimpleGUI have also recently added a 4th wrapper around Remi, which is a “GUI library for Python applications which transpiles an application’s interface into HTML to be rendered in a web browser”.
One of PySimpleGUI’s claims to fame is that you don’t need to use classes to create your user interfaces. This is an interesting way of doing things, but may turn off some users of the library.
Installing PySimpleGUI is a snap if you know how to use pip. Here’s the command you should run:
pip install pysimplegui
Note that this will install PySimpleGUI to your system Python. You may want to install it to a Virtual Python environment instead. You can use Python’s venv module to do that. Check it out!
Continue reading A Brief Intro to PySimpleGUI
The Portable Document Format (PDF) is a well-known format popularized by Adobe. It purports to create a document that should render the same across platforms.
Python has several libraries that you can use to work with PDFs:
- ReportLab – Creating PDFs
- PyPDF2 – Manipulating preexisting PDFs
- pdfrw – Also for manipulating preexisting PDFs, but also works with ReportLab
- PDFMiner – Extracts text from PDFs
There are several more Python PDF-related packages, but those four are probably the most well known. One common task of working with PDFs is the need for merging or concatenating multiple PDFs into one PDF. Another common task is taking a PDF and splitting out one or more of its pages into a new PDF.
You will be creating a graphical user interface that does both of these tasks using PyPDF2. Continue reading wxPython – Creating a PDF Merger / Splitter Utility
Let’s say you finished up a wonderful GUI application using wxPython. How do you share it with the world? This is always the dilemma when you finish an amazing program. Fortunately, there are several ways you can share your code. If you want to share your code with other developers, than Github or a similar website is definitely a good way to do. I won’t be covering using Git or Mercurial here. Instead what you will learn here is how to turn your application into an executable.
By turning your code into an executable, you can allow a user to just download the binary and run it without requiring them to download Python, your source code and your dependencies. All of those things will be bundled up into the executable instead.
There are many tools you can use to generate an executable:
You will be using PyInstaller in this tutorial. The main benefit to using PyInstaller is that it can generate executables for Windows, Mac and Linux. Note that it does not support cross-compiling. What that means is that you cannot run PyInstaller on Linux to create a Windows executable. Instead, PyInstaller will only create an executable for the OS that it is ran on. In other words, if you run PyInstaller on Windows, it will create a Windows executable only. Continue reading How to Distribute a wxPython Application
I am pleased to announce my latest book project, Creating GUI Applications with wxPython which I am running a Kickstarter campaign for.
Creating GUI Applications with wxPython is a book that will teach you how to use wxPython to create applications by actually creating several mini-programs. I have found that while learning how the various widgets work in wxPython is valuable, it is even better to learn by creating a simple application that does something useful.
The code in this book will be targeted for Python 3 only using wxPython 4.
For more information, please check out the Kickstarter.
I am happy to announce my latest Kickstarter which is to raise funds to create a book on Jupyter Notebook!
Jupyter Notebook 101Â will teach you all you need to know to create and use Notebooks effectively. You can use Jupyter Notebook to help you learn to code, create presentations, make beautiful documentation and much more!
The Jupyter Notebook is also used by the scientific community to demonstrate research in an easy-to-replicate manner.
You will learn the following inÂ Jupyter Notebook 101:
- How to create and edit Notebooks
- How to add styling, images, graphs, etc
- How to configure Notebooks
- How to export your Notebooks to other formats
- Notebook extensions
- Using Notebooks for presentations
- and more!
I am planning to release the book in November, 2018
You can learn more on Kickstarter!
Every now and then, someone will ask about how they can run the demo code from wxPython’s demo outside of the demo. In other words, they wonder how you can extract the code from the demo and run it in your own. I think I wrote about this very topic quite some time ago on the wxPython wiki, but I thought I should write on the topic here as well.
What to do about the log
The first issue that I always see is that the demo code is riddled with calls to some kind of log. It’s always writing to that log to help the developer see how different events get fired or how different methods get called. This is all well and good, but it makes just copying the code out of the demo difficult. Let’s take the code from the wx.ListBox demo as an example and see if we can make it work outside of the demo. Here is the demo code: Continue reading How to Use wxPython Demo Code Outside the Demo
Last time we got our Flask based music database application partially functional. It could now add data to the database, edit said data and also display everything in the database. But we didn’t cover how to filter the data by using the user’s filter choice (Artist, Album name or publisher name) and search string. We also didn’t cover how to delete items from the database. That is the two-fold goal of this article.
Filtering Search Results
Filtering search results using SQLAlchemy (via Flask-SQLAlchemy) is actually quite easy. All you need to do is create some very simple query objects. Open up the main.py file that we were editing last time and replace the search_results() function with the following version of the code: Continue reading Flask 101: Filtering Searches and Deleting Data
Last time we learned how to add a search form to our music database application. Of course, we still haven’t added any data to our database, so the search form doesn’t actually do much of anything except tell us that it didn’t find anything. In this tutorial we will learn how to actually add data, display search results and edit entries in the database.
Let’s get started!
Adding Data to the Database
Let’s start by coding up our new album form. Open up the “forms.py” file we created in the last tutorial and add the following class:
media_types = [('Digital', 'Digital'),
('Cassette Tape', 'Cassette Tape')
artist = StringField('Artist')
title = StringField('Title')
release_date = StringField('Release Date')
publisher = StringField('Publisher')
media_type = SelectField('Media', choices=media_types)
This defines all the fields we need to create a new Album. Now we need to open “main.py” and add a function to handle what happens when we want to create the new album. Continue reading Flask 101: Adding, Editing and Displaying Data
In our last article, we added a database to our Flask web application, but didn’t have a way to add anything to our database. We also didn’t have a way to view anything, so basically we ended up having a pretty useless web application. This article will take the time to teach you how to do the following:
- Create a form to add data to our database
- Use a form to edit data in our database
- Create some kind of view of what’s in the database
Adding forms to Flask is pretty easy too, once you figure out what extension to install. I had heard good things about WTForms so I will be using that in this tutorial. To install WTForms you will need to install Flask-WTF. Installing Flask-WTF is pretty easy; just open up your terminal and activate the virtual environment we set up in our first tutorial. Then run the following command using pip:
pip install Flask-WTF
This will install WTForms and Flask-WTF (along with any dependencies) to your web app’s virtual environment. Continue reading Flask 101: How to Add a Search Form
Last time we learned how to get Flask set up. In this article we will learn how to add a database to our music data website. As you might recall, Flask is a micro-web-framework. That means it doesn’t come with an Object Relational Mapper (ORM) like Django does. If you want to add database interactivity, then you need to add it yourself or install an extension. I personally like SQLAlchemy, so I thought it was nice that there is a ready-made extension for adding SQLAlchemy to Flask called Flask-SQLAlchemy.
To install Flask-SQLAlchemy, you just need to use pip. Make sure that you are in your activated virtual environment that we created in the first part of this series before you run the following or you’ll end up installing the extension to your base Python instead of your virtual environment:
pip install flask-sqlalchemy
Now that we have the Flask-SQLAlchemy installed along with its dependencies, we can get started creating a database! Continue reading Flask 101: Adding a Database