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

Python?ttkbootstrap?制作賬戶(hù)注冊(cè)信息界面的案例代碼

 更新時(shí)間:2022年02月18日 10:39:52   作者:終究不過(guò)路人  
ttkbootstrap 是一個(gè)基于 tkinter 的界面美化庫(kù),使用這個(gè)工具可以開(kāi)發(fā)出類(lèi)似前端 bootstrap 風(fēng)格的 tkinter 桌面程序。本文重點(diǎn)給大家介紹Python?ttkbootstrap?制作賬戶(hù)注冊(cè)信息界面的案例代碼,感興趣的朋友一起看看吧

前言

ttkbootstrap 是一個(gè)基于 tkinter 的界面美化庫(kù),使用這個(gè)工具可以開(kāi)發(fā)出類(lèi)似前端 bootstrap 風(fēng)格的 tkinter 桌面程序。
ttkbootstrap 不僅有豐富的案例,同時(shí)還有完善的官方文檔,可惜是英文的。不過(guò)對(duì)于程序員來(lái)說(shuō),只要用好翻譯軟件與提供的案例代碼,一樣可以輕松上手,那么接下來(lái)我們就介紹一下這個(gè)工具的使用。

準(zhǔn)備工作

首先肯定是需要安裝一下 ttkbootstrap

版本要新,最好不要用鏡像源安裝
pip install ttkbootstrap

import ttkbootstrap as ttk
from ttkbootstrap.constants import *
# root = tk.Tk()  # 使用 tkinter 創(chuàng)建窗口對(duì)象
root = ttk.Window()  # 使用 ttkbootstrap 創(chuàng)建窗口對(duì)象
root.geometry('300x150')
b1 = ttk.Button(root, text="按鈕 1", bootstyle=SUCCESS)  # 使用 ttkbootstrap 的組件
b1.pack(side=LEFT, padx=5, pady=10)
b2 = ttk.Button(root, text="按鈕 2", bootstyle=(INFO, OUTLINE))   # OUTLINE 是指定邊框線
b2.pack(side=LEFT, padx=5, pady=10)
root.mainloop()

開(kāi)始我們今天的案例教學(xué)

完整代碼,復(fù)制運(yùn)行即可(明示??????)

import ttkbootstrap as tk

root = tk.Window(themename='litera')
root.geometry('350x500+500+500')
root.title('萌新-注冊(cè)頁(yè)面')
root.wm_attributes('-topmost', 1)
username_str_var = tk.StringVar()
password_str_var = tk.StringVar()
# 0 女 1 男 -1 保密
gender_str_var = tk.IntVar()
# 興趣愛(ài)好
hobby_list = [
    [tk.IntVar(), '吃'],
    [tk.IntVar(), '喝'],
    [tk.IntVar(), '玩'],
    [tk.IntVar(), '樂(lè)'],
]
# 賬戶(hù)信息
tk.Label(root, width=10).grid()
tk.Label(root, text='用戶(hù)名:').grid(row=1, column=1, sticky=tk.W, pady=10)
tk.Entry(root, textvariable=username_str_var).grid(row=1, column=2, sticky=tk.W)
tk.Label(root, text='密  碼:').grid(row=2, column=1, sticky=tk.W, pady=10)
tk.Entry(root, textvariable=password_str_var).grid(row=2, column=2, sticky=tk.W)
# 性別 單選框
tk.Label(root, text='性別:').grid(row=4, column=1, sticky=tk.W, pady=10)
radio_frame = tk.Frame()
radio_frame.grid(row=4, column=2, sticky=tk.W)
tk.Radiobutton(radio_frame, text='男', variable=gender_str_var, value=1).pack(side=tk.LEFT, padx=5)
tk.Radiobutton(radio_frame, text='女', variable=gender_str_var, value=0).pack(side=tk.LEFT, padx=5)
tk.Radiobutton(radio_frame, text='保密', variable=gender_str_var, value=-1).pack(side=tk.LEFT, padx=5)
tk.Label(root, text='興趣:').grid(row=6, column=1, sticky=tk.W, pady=10)
check_frame = tk.Frame()
check_frame.grid(row=6, column=2, sticky=tk.W)
tk.Checkbutton(check_frame, text=hobby_list[0][1], variable=hobby_list[0][0]).pack(side=tk.LEFT, padx=5)
tk.Checkbutton(check_frame, text=hobby_list[1][1], variable=hobby_list[1][0], bootstyle="square-toggle").pack(
    side=tk.LEFT, padx=5)
tk.Checkbutton(check_frame, text=hobby_list[2][1], variable=hobby_list[2][0], bootstyle="round-toggle").pack(
tk.Checkbutton(check_frame, text=hobby_list[3][1], variable=hobby_list[3][0]).pack(side=tk.LEFT, padx=5)
# 生日
tk.Label(root, text='生日:').grid(row=7, column=1, sticky=tk.W, pady=10)
data_entry = tk.DateEntry()
data_entry.grid(row=7, column=2, sticky=tk.W, pady=10)
print(data_entry.entry.get())
# print(birth_day.get())
tk.Label(root, text="").grid(row=9, column=2, sticky=tk.W)
button = tk.Button(root, text='提交', width=20)
button.grid(row=10, column=2, sticky=tk.W)
def get_info():
    data = {
        '用戶(hù)名': username_str_var.get(),
        '密碼': password_str_var.get(),
        '性別': gender_str_var.get(),
        '興趣': [h for v, h in hobby_list if v.get()],
        '生日': data_entry.entry.get()
    }
    print(data)
    with open('1.txt', mode='a') as f:
        f.write('\n')
        f.write(str(data))
button.config(command=get_info)
root.mainloop()

1、做個(gè)界面

root = tk.Window(themename='litera')
root.geometry('350x500+500+500')
root.title('萌新-注冊(cè)頁(yè)面')
root.wm_attributes('-topmost', 1)
root.mainloop()

2、用戶(hù)注冊(cè)框

tk.Label(root, width=10).grid()
tk.Label(root, text='用戶(hù)名:').grid(row=1, column=1, sticky=tk.W, pady=10)
tk.Entry(root, textvariable=username_str_var).grid(row=1, column=2, sticky=tk.W)
tk.Label(root, text='密  碼:').grid(row=2, column=1, sticky=tk.W, pady=10)
tk.Entry(root, textvariable=password_str_var).grid(row=2, column=2, sticky=tk.W)

3、性別單選框

# 0 女 1 男 -1 保密
gender_str_var = tk.IntVar()

tk.Label(root, text='性別:').grid(row=4, column=1, sticky=tk.W, pady=10)
radio_frame = tk.Frame()
radio_frame.grid(row=4, column=2, sticky=tk.W)
tk.Radiobutton(radio_frame, text='男', variable=gender_str_var, value=1).pack(side=tk.LEFT, padx=5)
tk.Radiobutton(radio_frame, text='女', variable=gender_str_var, value=0).pack(side=tk.LEFT, padx=5)
tk.Radiobutton(radio_frame, text='保密', variable=gender_str_var, value=-1).pack(side=tk.LEFT, padx=5)

4、興趣愛(ài)好

hobby_list = [
    [tk.IntVar(), '吃'],
    [tk.IntVar(), '喝'],
    [tk.IntVar(), '玩'],
    [tk.IntVar(), '樂(lè)'],
]
tk.Label(root, text='興趣:').grid(row=6, column=1, sticky=tk.W, pady=10)
check_frame = tk.Frame()
check_frame.grid(row=6, column=2, sticky=tk.W)
tk.Checkbutton(check_frame, text=hobby_list[0][1], variable=hobby_list[0][0]).pack(side=tk.LEFT, padx=5)
tk.Checkbutton(check_frame, text=hobby_list[1][1], variable=hobby_list[1][0], bootstyle="square-toggle").pack(
    side=tk.LEFT, padx=5)
tk.Checkbutton(check_frame, text=hobby_list[2][1], variable=hobby_list[2][0], bootstyle="round-toggle").pack(
    side=tk.LEFT, padx=5)
tk.Checkbutton(check_frame, text=hobby_list[3][1], variable=hobby_list[3][0]).pack(side=tk.LEFT, padx=5)

5、生日

tk.Label(root, text='生日:').grid(row=7, column=1, sticky=tk.W, pady=10)
data_entry = tk.DateEntry()
data_entry.grid(row=7, column=2, sticky=tk.W, pady=10)
print(data_entry.entry.get())

6、提交信息按鈕

tk.Label(root, text="").grid(row=9, column=2, sticky=tk.W)
button = tk.Button(root, text='提交', width=20)
button.grid(row=10, column=2, sticky=tk.W)

7、保存數(shù)據(jù)

def get_info():
    data = {
        '用戶(hù)名': username_str_var.get(),
        '密碼': password_str_var.get(),
        '性別': gender_str_var.get(),
        '興趣': [h for v, h in hobby_list if v.get()],
        '生日': data_entry.entry.get()
    }
    print(data)
    with open('1.txt', mode='a') as f:
        f.write('\n')
        f.write(str(data))
button.config(command=get_info)

到此這篇關(guān)于Python ttkbootstrap 制作賬戶(hù)注冊(cè)信息界面的文章就介紹到這了,更多相關(guān)Python ttkbootstrap賬戶(hù)注冊(cè)界面內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • Python初學(xué)者需要注意的事項(xiàng)小結(jié)(python2與python3)

    Python初學(xué)者需要注意的事項(xiàng)小結(jié)(python2與python3)

    這篇文章主要介紹了Python初學(xué)者需要注意的事項(xiàng)小結(jié),包括了python2與python3的一些區(qū)別,需要的朋友可以參考下
    2018-09-09
  • Python實(shí)現(xiàn)字符串格式化輸出的方法詳解

    Python實(shí)現(xiàn)字符串格式化輸出的方法詳解

    這篇文章主要介紹了Python實(shí)現(xiàn)字符串格式化輸出的方法,結(jié)合具體實(shí)例形式總結(jié)分析了Python字符串格式化輸出的各種常用操作技巧,需要的朋友可以參考下
    2017-09-09
  • 詳解Python驗(yàn)證碼識(shí)別

    詳解Python驗(yàn)證碼識(shí)別

    這幾天在寫(xiě)一個(gè)程序的時(shí)候需要識(shí)別驗(yàn)證碼,因?yàn)槌绦蚴荘ython寫(xiě)的自然打算用Python進(jìn)行驗(yàn)證碼的識(shí)別。下面把實(shí)現(xiàn)思路分享在腳本之家平臺(tái),感興趣的朋友可以參考下
    2016-01-01
  • python實(shí)現(xiàn)html轉(zhuǎn)ubb代碼(html2ubb)

    python實(shí)現(xiàn)html轉(zhuǎn)ubb代碼(html2ubb)

    這篇文章主要介紹了python實(shí)現(xiàn)html轉(zhuǎn)ubb代碼(html2ubb),使用正則表達(dá)式寫(xiě)的一個(gè)函數(shù),需要的朋友可以參考下
    2014-07-07
  • python將下載到本地m3u8視頻合成MP4的代碼詳解

    python將下載到本地m3u8視頻合成MP4的代碼詳解

    這篇文章主要介紹了python將下載到本地m3u8視頻合成MP4的代碼詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-11-11
  • Python+Selenium實(shí)現(xiàn)短視頻自動(dòng)上傳與發(fā)布的實(shí)踐

    Python+Selenium實(shí)現(xiàn)短視頻自動(dòng)上傳與發(fā)布的實(shí)踐

    本文主要介紹了Python+Selenium實(shí)現(xiàn)短視頻自動(dòng)上傳與發(fā)布的實(shí)踐,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2022-04-04
  • python 使用百度AI接口進(jìn)行人臉對(duì)比的步驟

    python 使用百度AI接口進(jìn)行人臉對(duì)比的步驟

    這篇文章主要介紹了python 使用百度AI接口進(jìn)行人臉對(duì)比的步驟,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03
  • 如何在Flask中實(shí)現(xiàn)數(shù)據(jù)分組流程詳解

    如何在Flask中實(shí)現(xiàn)數(shù)據(jù)分組流程詳解

    在Flask中,數(shù)據(jù)分組是指將一組數(shù)據(jù)按照某種方式進(jìn)行分類(lèi),以便更好地對(duì)數(shù)據(jù)進(jìn)行處理和展示,可以使用Python內(nèi)置的itertools模塊中的groupby方法,或者使用SQL語(yǔ)句中的GROUP?BY子句來(lái)實(shí)現(xiàn)數(shù)據(jù)分組,這篇文章介紹了在Flask中實(shí)現(xiàn)數(shù)據(jù)分組,感興趣的同學(xué)可以參考下文
    2023-05-05
  • CentOS安裝pillow報(bào)錯(cuò)的解決方法

    CentOS安裝pillow報(bào)錯(cuò)的解決方法

    本文給大家分享的是作者在centos下為Python安裝pillow的時(shí)候報(bào)錯(cuò)的解決方法,希望對(duì)大家能夠有所幫助。
    2016-01-01
  • django Admin文檔生成器使用詳解

    django Admin文檔生成器使用詳解

    這篇文章主要介紹了django Admin文檔生成器,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-07-07

最新評(píng)論