歡迎您光臨本站 註冊首頁

基於Python的自媒體小助手---登錄頁面的實現代碼

←手機掃碼閱讀     qp18502452 @ 2020-06-30 , reply:0

核心技術:Python3.7

GUI技術:Tkinter (Python已經內置)

好多文章寫Python GUI之tkinter窗口視窗教程大集合(看這篇就夠了) 我看了N遍也沒夠好多東西都沒有就基本的介紹。。。還不夠。我搞這個也是為了項目服務先給大家來個截圖吧,其實知識點還是蠻多的。

在window上有點瑕疵了,在mac上海可以吧。使用到的技術我羅列一下完了在分享給大家代碼。

1、窗體設置標題和設置圖標,圖標格式是ICO的,一般我們事宜Png轉一下。https://www.easyicon.net/covert/ 這是轉換的網址。

2、Tkinter輸入控件、標籤控件、按鈕控件、複選框控件,我就不多說了網上有很多。需要注意的是密碼顯示要用show=‘*'

3、Tkinter 的place部局,就是絕對定位,因為不允許改變大小就絕對定位了。

4、按鈕事件傳參數需要使用lambda表達式。

5、背景色採用的是白色所以Lable的背景色都採用了白色。

6、最後一個就是屏幕居中,這個網上也一堆大家自己百度吧。

代碼如下:

  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+"用戶名不能為空! "      if len(passWord.get())==0:        errMessage=errMessage+"密碼不能為空!"      if errMessage!="":        messagebox.showinfo('提示', errMessage)      print(passWord.get())      pass

 

強調一下提示信息要一次性提示完畢,不用輸入完成用戶後在提示密碼,這個比較簡單寫起來也沒啥難度,對於輸入項目多的這個友好型一定要做到。

 

   


[qp18502452 ] 基於Python的自媒體小助手---登錄頁面的實現代碼已經有335次圍觀

http://coctec.com/docs/python/shhow-post-240416.html