python實(shí)戰(zhàn)練習(xí)之最新男女顏值打分小系統(tǒng)
導(dǎo)語(yǔ)
哈嘍!我是木木子,今天又想我了嘛?
之前不是出過(guò)一期Python美顏相機(jī)嘛?不知道你們還記得不?這一期的話(huà)話(huà)題還是圍繞上期關(guān)于顏值方面來(lái)走。
還是原來(lái)的配方,還是原來(lái)的味道。
偶爾有女生或者說(shuō)男生都有過(guò)這樣的經(jīng)歷,偶然照鏡子的時(shí)候覺(jué)得自己美、帥到爆炸?!拘【幋蛩啦粫?huì)承認(rèn)的.jpg】
但打開(kāi)無(wú)美顏的前置攝像頭無(wú)濾鏡,或者看到真正的漂亮小姐姐,又會(huì)感慨自己怎么能這么丑!
顏值打分其實(shí)是個(gè)很有爭(zhēng)議,并且人人都感興趣的話(huà)題,那么今天木木子就帶著Python顏值打分神器走來(lái)了!
如果滿(mǎn)分100分,平均分60,你會(huì)給自己的顏值打幾分?
正文
本文是基于tkinter做的界面化顏值打分小系統(tǒng)哈,快來(lái)測(cè)測(cè)你的顏值打多少分呀~
環(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'}
標(biāo)題設(shè)計(jì)顏色、字體等:
def title(self): """標(biāo)題設(shè)計(jì)""" lb = tk.Label(self.root, text='顏值打分系統(tǒng)', bg='#008B8B', fg='lightpink', font=('楷書(shū)', 30), width=20, height=2, # relief=tk.SUNKEN ) lb.place(x=200, y=10)
設(shè)置了界面化程序的背景大小等:
class ScoreSystem(): root = tk.Tk() # 修改程序框的大小 root.geometry('800x500') # 添加程序框標(biāo)題 root.title('顏值打分系統(tǒng)') # 修改背景色 canvas = tk.Canvas(root, width=800, # 指定Canvas組件的寬度 height=500, # 指定Canvas組件的高度 bg='#E6E8FA') # 指定Canvas組件的背景色 canvas.pack()
主函數(shù)運(yùn)行:
def start_interface(self): """主運(yùn)行函數(shù)""" self.title() self.time_component() # 打開(kāi)本地文件 tk.Button(self.root, text='打開(kāi)文件', command=self.show_original_pic).place(x=50, y=150) # 進(jìn)行顏值評(píng)分 tk.Button(self.root, text='顏值識(shí)別', command=self.open_files2).place(x=50, y=230) # 退出系統(tǒng) tk.Button(self.root, text='退出軟件', command=self.quit).place(x=50, y=390) # 顯示圖框標(biāo)題 tk.Label(self.root, text='原圖', font=10).place(x=380, y=120) # 修改圖片大小 self.label_img_original = tk.Label(self.root) # 設(shè)置顯示圖框背景 self.cv_orinial = tk.Canvas(self.root, bg='white', width=270, height=270) # 設(shè)置顯示圖框邊框 self.cv_orinial.create_rectangle(8, 8, 260, 260, width=1, outline='red') # 設(shè)置位置 self.cv_orinial.place(x=265, y=150) # 顯示圖片位置 self.label_img_original.place(x=265, y=150) # 設(shè)置評(píng)分標(biāo)簽 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='評(píng)分', 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) # 開(kāi)啟循環(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圖片對(duì)象 img_jpg_original = ImageTk.PhotoImage(img) # 設(shè)置圖片對(duì)象 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接口獲得的年齡、分?jǐn)?shù)、性別 age, score, gender = face_score(self.path_) # 清楚text文本框內(nèi)容并進(jìn)行插入 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()
最后還設(shè)置了時(shí)間組,隨時(shí)更新測(cè)試顏值的時(shí)間,就可以測(cè)出不同時(shí)間段顏值。
def get_time(self, lb): """獲取時(shí)間""" time_str = time.strftime("%Y-%m-%d %H:%M:%S") # 獲取當(dāng)前的時(shí)間并轉(zhuǎn)化為字符串 lb.configure(text=time_str) # 重新設(shè)置標(biāo)簽文本 self.root.after(1000, self.get_time, lb) # 每隔1s調(diào)用函數(shù) get_time自身獲取時(shí)間 def time_component(self): """時(shí)間組件""" lb = tk.Label(self.root, text='', fg='white', font=("黑體", 15)) lb.place(relx=0.75, rely=0.90) self.get_time(lb)
效果如下:
嘿嘿!僅僅供大家學(xué)習(xí)娛樂(lè)交流的~很多顏值打分不準(zhǔn)滴!請(qǐng)輕點(diǎn)兒捶我.jpg。
總結(jié)
好啦!文章就寫(xiě)到這里,這款顏值打分神器需要的小小伙伴兒自??!
mua~ 你們的支持是我最大的動(dòng)力??!
到此這篇關(guān)于python實(shí)戰(zhàn)練習(xí)之最新男女顏值打分小系統(tǒng)的文章就介紹到這了,更多相關(guān)python 男女顏值打分系統(tǒng)內(nèi)容請(qǐng)搜索本站以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持本站!
版權(quán)聲明:本站文章來(lái)源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來(lái)源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來(lái)源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來(lái),僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。