您好,登录后才能下订单哦!
这篇文章将为大家详细讲解有关如何实现基于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的自媒体小助手---登录页面就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。