In my experience, all GUI frameworks using Python (Tkinter, PyQT, etc.) seem to be a bit difficult to get started. So let’s take a look at one of my favorite and easiest ways to build GUIs using Python!
StreamlitThe package I like to use is Streamlit, the features it has are great. Here is a showcase of some front-end GUIs you can develop using this package:
If any of you using Looking at RShiny, they have some similarities. But I prefer Streamlit because it has a fairly modern design without having to spend a lot of time on front-end development.
If you want to develop web applications, this package may be perfect for you. Its core functionality is pretty basic, and while this package is nearly perfect for me, it may not be perfect for you.
Installation and developmentWe can use pip install. Run the following command in Terminal/Command Prompt:
pip install streamlit
Once the installation is complete, we can start using it!
Building a graphical user interfaceFirst, import the following packages:
import streamlit as st import numpy as np import pandas as pd import time
These are what we currently use to build a basic GUI Next, let’s name our application:
st.title('My first app')
Next, let’s build a table:
st.write(pd.DataFrame({ 'first column': [1, 2, 3, 4], 'second column': [10, 20, 30, 40] }))
This , we have a GUI that looks like this:
Streamlit also has a very cool built-in function that makes it easier to build GUIs. Without using the streamlit command mentioned above, the script below will also output the same results as above!
df = pd.DataFrame({ ‘first column’: [1, 2, 3, 4], ‘second column’: [10, 20, 30, 40] }) df
Next, let’s output our own chart in this GUI. In this example, we use a different dataset:
chart_data = pd.DataFrame( np.random.randn(20, 3), columns=[‘a’, ‘b’, ‘c’]) st.line_chart(chart_data)
This output basically looks like this in the GUI:
You've seen how easy it is to build web applications with Streamlit, and there's so much more you can do with this program. This is one of my favorite front-end development packages out there, I hope you like it too!
Official website address: https://streamlit.io/
Github address: https://github.com/streamlit/streamlitThe above is the detailed content of The easiest way to build a GUI using Python. For more information, please follow other related articles on the PHP Chinese website!