基于Python的自媒體小助手---登錄頁面的實(shí)現(xiàn)代碼
核心技術(shù):Python3.7
GUI技術(shù):Tkinter (Python已經(jīng)內(nèi)置)
好多文章寫Python GUI之tkinter窗口視窗教程大集合(看這篇就夠了) 我看了N遍也沒夠好多東西都沒有就基本的介紹。。。還不夠。我搞這個(gè)也是為了項(xiàng)目服務(wù)先給大家來個(gè)截圖吧,其實(shí)知識點(diǎn)還是蠻多的。
在window上有點(diǎn)瑕疵了,在mac上海可以吧。使用到的技術(shù)我羅列一下完了在分享給大家代碼。
1、窗體設(shè)置標(biāo)題和設(shè)置圖標(biāo),圖標(biāo)格式是ICO的,一般我們事宜Png轉(zhuǎn)一下。https://www.easyicon.net/covert/ 這是轉(zhuǎn)換的網(wǎng)址。
2、Tkinter輸入控件、標(biāo)簽控件、按鈕控件、復(fù)選框控件,我就不多說了網(wǎng)上有很多。需要注意的是密碼顯示要用show=‘*’
3、Tkinter 的place部局,就是絕對定位,因?yàn)椴辉试S改變大小就絕對定位了。
4、按鈕事件傳參數(shù)需要使用lambda表達(dá)式。
5、背景色采用的是白色所以Lable的背景色都采用了白色。
6、最后一個(gè)就是屏幕居中,這個(gè)網(wǎng)上也一堆大家自己百度吧。
代碼如下:
import tkinter as tkimport tkinter.font as tkFontfrom tkinter import messagebox class LoginView(): window = tk.Tk() def __init__(self): self.initializeUI() def initializeUI(self): self.window.iconbitmap('./resource/icon/hunter.ico') self.window.title(’獵人村自媒體小助手平臺登錄’) background_color='white' self.window.configure(background=background_color) #self.window.overrideredirect(True) photo = tk.PhotoImage(file='./resource/images/hunter.png') label = tk.Label(image=photo,width=32, bg=background_color) label.image = photo label.place(x=60,y=40) ft = tkFont.Font(family=’Fixdsys’, size=16, weight=tkFont.BOLD) tk.Label(self.window, text='獵人村自媒體小助手',font=ft, bg=background_color).place(x=100,y=44) photo = tk.PhotoImage(file='./resource/images/splitline.png') label = tk.Label(image=photo) label.image =photo label.place(x=0,y=90) # 標(biāo)簽 用戶名密碼 #F3F3F4 entryBackGroundColor='#F3F3F4' userNameFont = tkFont.Font(family=’Fixdsys’, size=10) tk.Label(self.window, text=’請輸入用戶名:’,font=userNameFont, bg=background_color).place(x=20, y=150) userName = tk.StringVar() tk.Entry(self.window, highlightthickness=1,bg=entryBackGroundColor,textvariable =userName).place(x=20, y=180,width=320, height=30) passWordFont = tkFont.Font(family=’Fixdsys’, size=10) passWord = tk.StringVar() # tk.Label(self.window, text=’請輸入密碼:’,font=passWordFont, bg=background_color).place(x=20, y=220) tk.Entry(self.window, highlightthickness=1, bg=entryBackGroundColor,textvariable =passWord, show=’*’).place(x=20, y=250,width=320, height=30) remeberMeFont=tkFont.Font(family=’Fixdsys’, size=12) tk.Checkbutton(self.window, text='記住我',fg='#0081FF',variable='0',font=remeberMeFont, bg=background_color).place(x=20, y=300) tk.Button(self.window, text=’立即登錄’, font=(’Fixdsys’, 14, ’bold’), width=29,fg=’white’,bg='#0081FF',command=lambda :self.login(userName,passWord)).place(x=20, y=330) regester_info=tkFont.Font(family=’Fixdsys’, size=10) tk.Label(self.window, text=’還沒有賬號?:’, font=regester_info, bg=background_color).place(x=102,y=375) tk.Label(self.window, text=’立即注冊’, font=regester_info, bg=background_color,fg='#FFA500').place(x=185,y=375) w = 370 h = 480 sw = self.window.winfo_screenwidth() # 得到屏幕寬度 sh = self.window.winfo_screenheight() # 得到屏幕高度 # 窗口寬高為100 x = (sw - w) / 2 y = (sh - h) / 2 self.window.geometry('%dx%d+%d+%d' % (w, h, x, y)) self.window.mainloop() pass def login(self,userName,passWord): errMessage='' if len(userName.get())==0: errMessage=errMessage+'用戶名不能為空!r' if len(passWord.get())==0: errMessage=errMessage+'密碼不能為空!' if errMessage!='': messagebox.showinfo(’提示’, errMessage) print(passWord.get()) pass
強(qiáng)調(diào)一下提示信息要一次性提示完畢,不用輸入完成用戶后在提示密碼,這個(gè)比較簡單寫起來也沒啥難度,對于輸入項(xiàng)目多的這個(gè)友好型一定要做到。
總結(jié)
到此這篇關(guān)于基于Python的自媒體小助手---登錄頁面的文章就介紹到這了,更多相關(guān)Python自媒體小助手內(nèi)容請搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
相關(guān)文章:
1. 用xslt+css讓RSS顯示的跟網(wǎng)頁一樣漂亮2. ASP.NET MVC把數(shù)據(jù)庫中枚舉項(xiàng)的數(shù)字轉(zhuǎn)換成文字3. 《CSS3實(shí)戰(zhàn)》筆記--漸變設(shè)計(jì)(一)4. 測試模式 - XSL教程 - 55. Ajax實(shí)現(xiàn)異步加載數(shù)據(jù)6. 教你JS更簡單的獲取表單中數(shù)據(jù)(formdata)7. ASP.NET Core自定義中間件的方式詳解8. html5手機(jī)觸屏touch事件介紹9. CSS3實(shí)現(xiàn)動態(tài)翻牌效果 仿百度貼吧3D翻牌一次動畫特效10. 讓chatgpt將html中的圖片轉(zhuǎn)為base64方法示例
