基于Python的自媒體小助手---登錄頁面的實現(xiàn)代碼
核心技術:Python3.7
GUI技術:Tkinter (Python已經(jīng)內(nèi)置)
好多文章寫Python GUI之tkinter窗口視窗教程大集合(看這篇就夠了) 我看了N遍也沒夠好多東西都沒有就基本的介紹。。。還不夠。我搞這個也是為了項目服務先給大家來個截圖吧,其實知識點還是蠻多的。

在window上有點瑕疵了,在mac上??梢园?。使用到的技術我羅列一下完了在分享給大家代碼。
1、窗體設置標題和設置圖標,圖標格式是ICO的,一般我們事宜Png轉一下。https://www.easyicon.net/covert/ 這是轉換的網(wǎng)址。
2、Tkinter輸入控件、標簽控件、按鈕控件、復選框控件,我就不多說了網(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)
# 標簽 用戶名密碼 #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)一下提示信息要一次性提示完畢,不用輸入完成用戶后在提示密碼,這個比較簡單寫起來也沒啥難度,對于輸入項目多的這個友好型一定要做到。
總結
到此這篇關于基于Python的自媒體小助手---登錄頁面的文章就介紹到這了,更多相關Python自媒體小助手內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
對python抓取需要登錄網(wǎng)站數(shù)據(jù)的方法詳解
今天小編就為大家分享一篇對python抓取需要登錄網(wǎng)站數(shù)據(jù)的方法詳解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05
使用Python做定時任務及時了解互聯(lián)網(wǎng)動態(tài)
這篇文章主要介紹了使用Python做定時任務及時了解互聯(lián)網(wǎng)動態(tài),需要的朋友可以參考下2019-05-05
淺談Scrapy網(wǎng)絡爬蟲框架的工作原理和數(shù)據(jù)采集
在python爬蟲中:requests + selenium 可以解決目前90%的爬蟲需求,難道scrapy 是解決剩下的10%的嗎?顯然不是。scrapy框架是為了讓我們的爬蟲更強大、更高效。接下來我們一起學習一下它吧。2019-02-02
使用python實現(xiàn)CNN-GRU故障診斷的代碼示例
這篇文章主要給大家詳細介紹了如何使用python實現(xiàn)CNN-GRU故障診斷,文章中有詳細的代碼示例,具有一定的參考價值,需要的朋友可以參考下2023-07-07
Python實現(xiàn)指定范圍內(nèi)篩選并剔除Excel表格中的數(shù)據(jù)
這篇文章主要為大家詳細介紹了Python如何實現(xiàn)在指定范圍內(nèi)篩選并剔除Excel表格中的數(shù)據(jù),文中的示例代碼講解詳細,感興趣的可以了解一下2023-06-06

