Home > Backend Development > Python Tutorial > The easiest way to build a GUI using Python

The easiest way to build a GUI using Python

王林
Release: 2023-04-10 14:01:04
forward
1819 people have browsed it

The easiest way to build a GUI using Python

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!

Streamlit

The 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:

The easiest way to build a GUI using Python

The easiest way to build a GUI using Python

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 development

We can use pip install. Run the following command in Terminal/Command Prompt:

pip install streamlit
Copy after login

Once the installation is complete, we can start using it!

Building a graphical user interface

First, import the following packages:

import streamlit as st
import numpy as np
import pandas as pd
import time
Copy after login

These are what we currently use to build a basic GUI Next, let’s name our application:

st.title('My first app')
Copy after login

Next, let’s build a table:

st.write(pd.DataFrame({
'first column': [1, 2, 3, 4],
'second column': [10, 20, 30, 40]
}))
Copy after login

This , we have a GUI that looks like this:

The easiest way to build a GUI using Python

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
Copy after login

The easiest way to build a GUI using Python

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)
Copy after login

This output basically looks like this in the GUI:

The easiest way to build a GUI using Python

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/streamlit

The 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!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template