您的位置:首页技术文章
文章详情页

基于Python的自媒体小助手---登录页面的实现代码

【字号: 日期:2022-07-19 11:57:07浏览:69作者:猪猪

核心技术:Python3.7

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

好多文章写Python GUI之tkinter窗口视窗教程大集合(看这篇就够了) 我看了N遍也没够好多东西都没有就基本的介绍。。。还不够。我搞这个也是为了项目服务先给大家来个截图吧,其实知识点还是蛮多的。

基于Python的自媒体小助手---登录页面的实现代码

在window上有点瑕疵了,在mac上海可以吧。使用到的技术我罗列一下完了在分享给大家代码。

1、窗体设置标题和设置图标,图标格式是ICO的,一般我们事宜Png转一下。https://www.easyicon.net/covert/ 这是转换的网址。

2、Tkinter输入控件、标签控件、按钮控件、复选框控件,我就不多说了网上有很多。需要注意的是密码显示要用show=‘*’

3、Tkinter 的place部局,就是绝对定位,因为不允许改变大小就绝对定位了。

4、按钮事件传参数需要使用lambda表达式。

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

6、最后一个就是屏幕居中,这个网上也一堆大家自己百度吧。

代码如下:

import tkinter as tkimport tkinter.font as tkFontfrom 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的自媒体小助手---登录页面的实现代码

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

总结

到此这篇关于基于Python的自媒体小助手---登录页面的文章就介绍到这了,更多相关Python自媒体小助手内容请搜索好吧啦网以前的文章或继续浏览下面的相关文章希望大家以后多多支持好吧啦网!

标签: Python 编程
相关文章: