基于Python的自媒体小助手---登录页面

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

强调一下提示信息要一次性提示完毕,不用输入完成用户后在提示密码,这个比较简单写起来也没啥难度,对于输入项目多的这个友好型一定要做到。

先到这了有时间在和大家分享~

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亚丁号

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值