python實戰(zhàn)練習之最新男女顏值打分小系統(tǒng)
導語
哈嘍!我是木木子,今天又想我了嘛?
之前不是出過一期Python美顏相機嘛?不知道你們還記得不?這一期的話話題還是圍繞上期關于顏值方面來走。
還是原來的配方,還是原來的味道。
偶爾有女生或者說男生都有過這樣的經(jīng)歷,偶然照鏡子的時候覺得自己美、帥到爆炸?!拘【幋蛩啦粫姓J的.jpg】
但打開無美顏的前置攝像頭無濾鏡,或者看到真正的漂亮小姐姐,又會感慨自己怎么能這么丑!
顏值打分其實是個很有爭議,并且人人都感興趣的話題,那么今天木木子就帶著Python顏值打分神器走來了!
如果滿分100分,平均分60,你會給自己的顏值打幾分?
正文
本文是基于tkinter做的界面化顏值打分小系統(tǒng)哈,快來測測你的顏值打多少分呀~
環(huán)境安裝部分:Python3、pycharm2021、以及一些自帶的模塊。
pip install -i https://pypi.douban.com/simple/ pillow pip install -i https://pypi.douban.com/simple/ baidu-aip
首先還是肯定配置百度api參數(shù)如下:
APP_ID = '15768642'
API_KEY = 'xhiiGmGPRCRj10XIqVlVeCky'
SECRET_KEY = 'ZDMMAO7StwTKzW8BspVQxvoGtdgSW4yI'
a_face = AipFace(APP_ID, API_KEY, SECRET_KEY)
image_type = 'BASE64'
options = {'face_field': 'age,gender,beauty'}
標題設計顏色、字體等:
def title(self):
"""標題設計"""
lb = tk.Label(self.root, text='顏值打分系統(tǒng)',
bg='#008B8B',
fg='lightpink', font=('楷書', 30),
width=20,
height=2,
# relief=tk.SUNKEN
)
lb.place(x=200, y=10)
設置了界面化程序的背景大小等:
class ScoreSystem():
root = tk.Tk()
# 修改程序框的大小
root.geometry('800x500')
# 添加程序框標題
root.title('顏值打分系統(tǒng)')
# 修改背景色
canvas = tk.Canvas(root,
width=800, # 指定Canvas組件的寬度
height=500, # 指定Canvas組件的高度
bg='#E6E8FA') # 指定Canvas組件的背景色
canvas.pack()
主函數(shù)運行:
def start_interface(self):
"""主運行函數(shù)"""
self.title()
self.time_component()
# 打開本地文件
tk.Button(self.root, text='打開文件', command=self.show_original_pic).place(x=50, y=150)
# 進行顏值評分
tk.Button(self.root, text='顏值識別', command=self.open_files2).place(x=50, y=230)
# 退出系統(tǒng)
tk.Button(self.root, text='退出軟件', command=self.quit).place(x=50, y=390)
# 顯示圖框標題
tk.Label(self.root, text='原圖', font=10).place(x=380, y=120)
# 修改圖片大小
self.label_img_original = tk.Label(self.root)
# 設置顯示圖框背景
self.cv_orinial = tk.Canvas(self.root, bg='white', width=270, height=270)
# 設置顯示圖框邊框
self.cv_orinial.create_rectangle(8, 8, 260, 260, width=1, outline='red')
# 設置位置
self.cv_orinial.place(x=265, y=150)
# 顯示圖片位置
self.label_img_original.place(x=265, y=150)
# 設置評分標簽
tk.Label(self.root, text='性別', font=10).place(x=680, y=150)
self.text1 = tk.Text(self.root, width=10, height=2)
tk.Label(self.root, text='年齡', font=10).place(x=680, y=250)
self.text2 = tk.Text(self.root, width=10, height=2)
tk.Label(self.root, text='評分', font=10).place(x=680, y=350)
self.text3 = tk.Text(self.root, width=10, height=2)
# 填裝文字
self.text1.place(x=680, y=175)
self.text2.place(x=680, y=285)
self.text3.place(x=680, y=385)
# 開啟循環(huán)
self.root.mainloop()
def show_original_pic(self):
"""放入文件"""
self.path_ = askopenfilename(title='選擇文件')
# 處理文件
img = Image.open(fr'{self.path_}')
img = img.resize((270, 270), PIL.Image.ANTIALIAS) # 調(diào)整圖片大小至270*270
# 生成tkinter圖片對象
img_jpg_original = ImageTk.PhotoImage(img)
# 設置圖片對象
self.label_img_original.config(image=img_jpg_original)
self.label_img_original.image = img_jpg_original
self.cv_orinial.create_image(5, 5, anchor='nw', image=img_jpg_original)
def open_files2(self):
# 獲取百度API接口獲得的年齡、分數(shù)、性別
age, score, gender = face_score(self.path_)
# 清楚text文本框內(nèi)容并進行插入
self.text1.delete(1.0, tk.END)
self.text1.tag_config('red', foreground='RED')
self.text1.insert(tk.END, gender, 'red')
self.text2.delete(1.0, tk.END)
self.text2.tag_config('red', foreground='RED')
self.text2.insert(tk.END, age, 'red')
self.text3.delete(1.0, tk.END)
self.text3.tag_config('red', foreground='RED')
self.text3.insert(tk.END, score, 'red')
def quit(self):
"""退出"""
self.root.quit()
最后還設置了時間組,隨時更新測試顏值的時間,就可以測出不同時間段顏值。
def get_time(self, lb):
"""獲取時間"""
time_str = time.strftime("%Y-%m-%d %H:%M:%S") # 獲取當前的時間并轉(zhuǎn)化為字符串
lb.configure(text=time_str) # 重新設置標簽文本
self.root.after(1000, self.get_time, lb) # 每隔1s調(diào)用函數(shù) get_time自身獲取時間
def time_component(self):
"""時間組件"""
lb = tk.Label(self.root, text='', fg='white', font=("黑體", 15))
lb.place(relx=0.75, rely=0.90)
self.get_time(lb)
效果如下:



嘿嘿!僅僅供大家學習娛樂交流的~很多顏值打分不準滴!請輕點兒捶我.jpg。
總結
好啦!文章就寫到這里,這款顏值打分神器需要的小小伙伴兒自??!
mua~ 你們的支持是我最大的動力?。?/p>

到此這篇關于python實戰(zhàn)練習之最新男女顏值打分小系統(tǒng)的文章就介紹到這了,更多相關python 男女顏值打分系統(tǒng)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
python實現(xiàn)可將字符轉(zhuǎn)換成大寫的tcp服務器實例
這篇文章主要介紹了python實現(xiàn)可將字符轉(zhuǎn)換成大寫的tcp服務器,通過tcp服務器端實現(xiàn)針對字符的轉(zhuǎn)換與返回功能,具有一定參考借鑒價值,需要的朋友可以參考下2015-04-04
Python面試之os.system()和os.popen()的區(qū)別詳析
Python調(diào)用Shell,有兩種方法:os.system(cmd)或os.popen(cmd)腳本執(zhí)行過程中的輸出內(nèi)容,下面這篇文章主要給大家介紹了關于Python面試之os.system()和os.popen()區(qū)別的相關資料,需要的朋友可以參考下2022-06-06
Pycharm自動添加文件頭注釋和函數(shù)注釋參數(shù)的方法
這篇文章主要介紹了Pycharm自動添加文件頭注釋和函數(shù)注釋參數(shù),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2020-10-10
python如何標準化日期時間格式轉(zhuǎn)化成非標準化格式
這篇文章主要介紹了python如何標準化日期時間格式轉(zhuǎn)化成非標準化格式問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-06-06

