基于Python的自媒體小助手---登錄頁面的實現(xiàn)代碼
核心技術(shù):Python3.7
GUI技術(shù):Tkinter (Python已經(jīng)內(nèi)置)
好多文章寫Python GUI之tkinter窗口視窗教程大集合(看這篇就夠了) 我看了N遍也沒夠好多東西都沒有就基本的介紹。。。還不夠。我搞這個也是為了項目服務(wù)先給大家來個截圖吧,其實知識點還是蠻多的。
在window上有點瑕疵了,在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部局,就是絕對定位,因為不允許改變大小就絕對定位了。
4、按鈕事件傳參數(shù)需要使用lambda表達式。
5、背景色采用的是白色所以Lable的背景色都采用了白色。
6、最后一個就是屏幕居中,這個網(wǎng)上也一堆大家自己百度吧。
代碼如下:
import tkinter as tk import tkinter.font as tkFont from 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
強調(diào)一下提示信息要一次性提示完畢,不用輸入完成用戶后在提示密碼,這個比較簡單寫起來也沒啥難度,對于輸入項目多的這個友好型一定要做到。
總結(jié)
到此這篇關(guān)于基于Python的自媒體小助手---登錄頁面的文章就介紹到這了,更多相關(guān)Python自媒體小助手內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
python中split(),?os.path.split()和os.path.splitext()的用法
本文主要介紹了python中split(),?os.path.split()和os.path.splitext()的用法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02Python中使用pypdf2合并、分割、加密pdf文件的代碼詳解
這篇文章主要介紹了Python中使用pypdf2合并、分割、加密pdf文件的代碼,本文通過實例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下2019-05-05Python Flask 和 Django 的區(qū)別與適用場景示例分析
Flask和Django是兩個流行的Python Web框架,但設(shè)計哲學(xué)、功能和用法有很大區(qū)別,Flask是一個輕量級框架,簡單靈活,適合小型項目和快速原型開發(fā),本文給大家介紹Python Flask 和 Django 的區(qū)別與適用場景示例分析,感興趣的朋友跟隨小編一起看看吧2024-10-10