欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python+streamlit實(shí)現(xiàn)輕松創(chuàng)建人事系統(tǒng)

 更新時間:2023年02月28日 08:34:20   作者:Python數(shù)據(jù)開發(fā)  
streamlit 是 基于 Python 的一個非常強(qiáng)大的 web 構(gòu)建系統(tǒng),通過該類庫,我們可以實(shí)現(xiàn)不需要編寫一行前端代碼而構(gòu)建一個完整的 Web 應(yīng)用。下面我們就來編寫一個簡單的人事系統(tǒng)吧

系統(tǒng)簡介

這個簡單的人事系統(tǒng)包含了添加員工和顯示員工列表兩個功能。在 Streamlit 庫中,可以使用 st.sidebar 創(chuàng)建側(cè)邊欄,其中可以包含各種菜單選項。在選擇菜單選項后,可以使用 st.write 和 st.dataframe 顯示文本和數(shù)據(jù)表格。此外,可以使用 st.text_input 和 st.number_input 創(chuàng)建輸入框,讓用戶輸入員工信息,并使用 st.button 創(chuàng)建按鈕來觸發(fā)添加員工操作。最后,在程序主函數(shù)中調(diào)用以上各個函數(shù)即可。

代碼詳情

我們先導(dǎo)入相關(guān)依賴,并創(chuàng)建員工類

import streamlit as st
import pandas as pd

# 創(chuàng)建員工類
class Employee:
    def __init__(self, name, age, position):
        self.name = name
        self.age = age
        self.position = position

接下來我們編寫員工函數(shù),導(dǎo)入員工數(shù)據(jù)

# 創(chuàng)建員工列表
employee_list = []

# 添加員工函數(shù)
def add_employee(name, age, position):
    employee = Employee(name, age, position)
    employee_list.append(employee)

# 顯示員工列表函數(shù)
def show_employee_list():
    if len(employee_list) == 0:
        st.write('員工列表為空!')
    else:
        df = pd.DataFrame([[e.name, e.age, e.position] for e in employee_list], columns=['姓名', '年齡', '職位'])
        st.dataframe(df)

最后就是添加頁面部分以及主程序

# 添加員工界面
def add_employee_page():
    st.write('添加新員工')
    name = st.text_input('姓名')
    age = st.number_input('年齡', min_value=0, max_value=100)
    position = st.text_input('職位')
    if st.button('添加'):
        add_employee(name, age, position)
        st.success('添加成功!')

# 顯示員工列表界面
def show_employee_list_page():
    st.write('員工列表')
    show_employee_list()

# 主程序
def main():
    st.title('人事系統(tǒng)')
    menu = ['添加員工', '員工列表']
    choice = st.sidebar.selectbox('選擇菜單', menu)
    if choice == '添加員工':
        add_employee_page()
    elif choice == '員工列表':
        show_employee_list_page()

完整代碼

import streamlit as st
import pandas as pd

# 創(chuàng)建員工類
class Employee:
    def __init__(self, name, age, position):
        self.name = name
        self.age = age
        self.position = position

# 創(chuàng)建員工列表
employee_list = []

# 添加員工函數(shù)
def add_employee(name, age, position):
    employee = Employee(name, age, position)
    employee_list.append(employee)

# 顯示員工列表函數(shù)
def show_employee_list():
    if len(employee_list) == 0:
        st.write('員工列表為空!')
    else:
        df = pd.DataFrame([[e.name, e.age, e.position] for e in employee_list], columns=['姓名', '年齡', '職位'])
        st.dataframe(df)

# 添加員工界面
def add_employee_page():
    st.write('添加新員工')
    name = st.text_input('姓名')
    age = st.number_input('年齡', min_value=0, max_value=100)
    position = st.text_input('職位')
    if st.button('添加'):
        add_employee(name, age, position)
        st.success('添加成功!')

# 顯示員工列表界面
def show_employee_list_page():
    st.write('員工列表')
    show_employee_list()

# 主程序
def main():
    st.title('人事系統(tǒng)')
    menu = ['添加員工', '員工列表']
    choice = st.sidebar.selectbox('選擇菜單', menu)
    if choice == '添加員工':
        add_employee_page()
    elif choice == '員工列表':
        show_employee_list_page()

if __name__ == '__main__':
    main()

到此這篇關(guān)于Python+streamlit實(shí)現(xiàn)輕松創(chuàng)建人事系統(tǒng)的文章就介紹到這了,更多相關(guān)Python streamlit人事系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論