资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

如何实现基于Python的自媒体小助手---登录页面-创新互联

创新互联www.cdcxhl.cn八线动态BGP香港云服务器提供商,新人活动买多久送多久,划算不套路!

公司主营业务:网站制作、成都网站制作、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联推出杭锦免费做网站回馈大家。

这篇文章将为大家详细讲解有关如何实现基于Python的自媒体小助手---登录页面,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。

核心技术:Python3.7

GUI技术:Tkinter (Python已经内置)

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

分享标题:如何实现基于Python的自媒体小助手---登录页面-创新互联
网站路径:http://cdkjz.cn/article/digjdp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220