python實戰(zhàn)練習之最新男女顏值打分小系統(tǒng)
導語
哈嘍!我是木木子,今天又想我了嘛?
之前不是出過一期Python美顏相機嘛?不知道你們還記得不?這一期的話話題還是圍繞上期關于顏值方面來走。
還是原來的配方,還是原來的味道。
偶爾有女生或者說男生都有過這樣的經(jīng)歷,偶然照鏡子的時候覺得自己美、帥到爆炸。【小編打死不會承認的.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) # 調整圖片大小至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文本框內容并進行插入
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") # 獲取當前的時間并轉化為字符串
lb.configure(text=time_str) # 重新設置標簽文本
self.root.after(1000, self.get_time, lb) # 每隔1s調用函數(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)內容請搜索本站以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持本站!
版權聲明:本站文章來源標注為YINGSOO的內容版權均為本站所有,歡迎引用、轉載,請保持原文完整并注明來源及原文鏈接。禁止復制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務器上建立鏡像,否則將依法追究法律責任。本站部分內容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學習參考,不代表本站立場,如有內容涉嫌侵權,請聯(lián)系alex-e#qq.com處理。
關注官方微信