Data science and Machine Learning GUI programs/ desktop apps with PySimpleGUI package
MIT License
Data science GUI programs with awesome PySimpleGUI
package.
PySimpleGUI
and what is this repo?As per their website, "Python GUI For Humans - Transforms tkinter, Qt, Remi, WxPython into portable people-friendly Pythonic interfaces". In this repo, I specifically focus on creating simple demo programs related to data science (simple analytics, statistical modeling and visualizations, basic machine learning) using this powerful GUI building tool.
Install PySimpleGUI
by,
pip install pysimplegui
You will also need,
etc. to run the demo codes.
Here is the code to program this app,
import PySimpleGUI as sg
import numpy as np
# Update function
def update():
r = np.random.randint(1,100)
text_elem = window['-text-']
text_elem.update("This is a random integer: {}".format(r))
# Define the window's contents i.e. layout
layout = [[sg.Button('Generate',enable_events=True, key='-FUNCTION-', font='Helvetica 16')],
[sg.Text('This is a random integer:', size=(25, 1), key='-text-', font='Helvetica 16')]]
# Create the window
window = sg.Window('Generate random integer', layout, size=(350,100))
# Event loop
while True:
event, values = window.read()
if event in (sg.WIN_CLOSED, 'Exit'):
break
if event == '-FUNCTION-':
update()
# Close the window i.e. release resource
window.close()
When you save this code in a Python script and run it, you will see a simple window pop up where you can click on a button to call the update
function as many times as you want (note the while True
loop in the code for this infinite loop action) and generate a random integer between 1 and 99.
Although this is a very simple code, it features,
size
and font
) and a windowWe can essentially follow the same path and add more layers of layout, events, logic, and widgets to make powerful data science apps.
FontUpdate.py
)Just run with python FontUpdate.py
command and you will see this window pop up where you can dynamically update the font of the text. Here is the demo video,
This app gets you familiar with other widgets available,
Just run with python QuadraticEquation.py
command and you will see this window pop up where you can enter coefficients of a quadratic equation and get the solution (even if the roots turn out to be complex numbers!)
SimpleDataFrame.py
(Pandas DataFrame app)There are both Jupyter notebooks and .PY scripts. The simplest way to run a GUI is to execute the .PY scripts, e.g.
python SimpleDataFrame.py
At the start, it will ask you for a dataset file (a CSV)
When you click on the 'Browse' button, it will show a file browser dialog first. Make sure you select the correct dataset for this demo from under the data
directory.
After you select the cars.csv
, you will see other prompts popping up,
If you click 'Yes' on that last prompt, you will see the dataset that was read in a new window,
After you close that window, a new popup will ask if you want to see the descriptive statistics about this dataset. If you click 'Yes', then you will see something like this,
After you close that window, another popup will ask if you want to see a sample plot. If you click 'Yes', then you will see something like this,
If you want to experiment with the code, you can look at the Notebooks and play with them.
Generate as many random scatter plots as you wish.
A simple 2nd degree polynomial fitting app wher you can adjust the noise level of the randomly generated data.
We build a simple app which lets you load the Pima Indians diabetes dataset and fit a Random Forest model to this data using Scikit-learn in the background.
Qt Desginer is a popular visual aid for building complex forms for Python GUI programming. You can build PySimpleGUI comppatible code with Qt Designer by using an intermediary - PySimpleGUIDesigner
.
Here is the Github for that program.
And, here is an YouTube tutorial on how to use it.