【颜值打分小程序】最火爆的“颜值测试”,做还是不做?(疯狂打call)
前言
大家好!我是梨子同學!
希望大家多多支持我!哈哈
為了感謝每一個關注我的小可愛:💓每篇文章的項目源碼都是無償分享滴💓👇👇👇
點這里藍色這行字體自取,需要什么源碼記得說標題名字哈!私信我也可!
小編也一直在學習編程,如果代碼小程序出現錯誤歡迎大家評論區留言哈!
最后——如果文章有幫助到你,記得“關注”、“點贊”、“評論”三連哦~
正文
偶爾有女生或者說男生都有過這樣的經歷,偶然照鏡子的時候覺得自己美、帥到爆炸。
但打開無美顏的前置攝像頭無濾鏡,或者看到真正的漂亮小姐姐,又會感慨自己怎么能這么丑!
?
?顏值打分其實是個很有爭議,并且人人都感興趣的話題,那么今天小編就帶著Python顏值打分
神器走來了!如果滿分100分,平均分60,你會給自己的顏值打幾分?
一、代碼部分
本文是基于tkinter做的界面化顏值打分小系統哈,快來測測你的顏值打多少分呀~
環境安裝部分:Python3、pycharm2021、以及一些自帶的模塊。
pip install -i https://pypi.douban.com/simple/ pillow pip install -i https://pypi.douban.com/simple/ baidu-aip?首先還是肯定配置百度api參數如下:
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='顏值打分系統',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('顏值打分系統')# 修改背景色canvas = tk.Canvas(root,width=800, # 指定Canvas組件的寬度height=500, # 指定Canvas組件的高度bg='#E6E8FA') # 指定Canvas組件的背景色canvas.pack()主函數運行:
def start_interface(self):"""主運行函數"""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)# 退出系統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)# 開啟循環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_png_original = ImageTk.PhotoImage(img)# 設置圖片對象self.label_img_original.config(image=img_png_original)self.label_img_original.image = img_png_originalself.cv_orinial.create_image(5, 5, anchor='nw', image=img_png_original)def open_files2(self):# 獲取百度API接口獲得的年齡、分數、性別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調用函數 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)二、效果展示
隨機第一組俄羅斯小姐姐:
隨機第二組小哥哥:
隨機第三組可愛小姐姐:
?嘿嘿!僅僅供大家學習娛樂交流的~很多顏值打分不準滴!
總結
好啦!文章就寫到這里,這款顏值打分神器需要的小小伙伴兒自取!
關注小編獲取更多精彩內容!記得點擊傳送門哈👇
??制作不易,記得一鍵三連哦!!?如需打包好的源碼+素材免費分享滴!!傳送門
總結
以上是生活随笔為你收集整理的【颜值打分小程序】最火爆的“颜值测试”,做还是不做?(疯狂打call)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《极速切水果游戏》有Python版了,曾
- 下一篇: 【Python植物大战僵尸军团来袭】“大