python机电管理系统gui版_Python学习之GUI--登录系统篇

我的python环境是:python3.6.5

这里我选择的GUI编程包是:tkinter

tkinker在python2.5以后就是自带包了,所以我们不需要另外安装

tkinker相对与其他python GUI编程的包而已,是相对容易入手的

我们先上代码:

#这是系统的登录界面

import tkinter

from tkinter import messagebox

# 下面是我为这个登录系统写的一些其他文件,可以暂时把他们当作系统包来看

import siginUp,managementOperation,SQLGenerator,SQLOperation,verifyAccount

class Login(object):

def __init__(self):

# 创建主窗口,用于容纳其它组件

self.root = tkinter.Tk()

# 给主窗口设置标题内容

self.root.title("影视资源管理系统(离线版)")

self.root.geometry('450x300')

self.canvas = tkinter.Canvas(self.root, height=200, width=500)#创建画布

self.image_file = tkinter.PhotoImage(file='welcome_1.gif')#加载图片文件

self.image = self.canvas.create_image(0,0, anchor='nw', image=self.image_file)#将图片置于画布上

self.canvas.pack(side='top')#放置画布(为上端)

#创建一个`label`名为`Account: `

self.label_account = tkinter.Label(self.root, text='Account: ')

#创建一个`label`名为`Password: `

self.label_password = tkinter.Label(self.root, text='Password: ')

# 创建一个账号输入框,并设置尺寸

self.input_account = tkinter.Entry(self.root, width=30)

# 创建一个密码输入框,并设置尺寸

self.input_password = tkinter.Entry(self.root, show='*', width=30)

# 创建一个登录系统的按钮

self.login_button = tkinter.Button(self.root, command = self.backstage_interface, text = "Login", width=10)

# 创建一个注册系统的按钮

self.siginUp_button = tkinter.Button(self.root, command = self.siginUp_interface, text = "Sign up", width=10)

# 完成布局

def gui_arrang(self):

self.label_account.place(x=60, y= 170)

self.label_password.place(x=60, y= 195)

self.input_account.place(x=135, y=170)

self.input_password.place(x=135, y=195)

self.login_button.place(x=140, y=235)

self.siginUp_button.place(x=240, y=235)

# 进入注册界面

def siginUp_interface(self):

# self.root.destroy()

siginUp.main()

# 进行登录信息验证

def backstage_interface(self):

account = self.input_account.get().ljust(10," ")

password = self.input_password.get().ljust(10," ")

#对账户信息进行验证,普通用户返回user,管理员返回master,账户错误返回noAccount,密码错误返回noPassword

verifyResult = verifyAccount.verifyAccountData(account,password)

if verifyResult=='master':

self.root.destroy()

managementOperation.main()

elif verifyResult=='user':

self.root.destroy()

managementOperation.main()

elif verifyResult=='noAccount':

tkinter.messagebox.showinfo(title='影视资源管理系统', message='该账号不存在请重新输入!')

elif verifyResult=='noPassword':

tkinter.messagebox.showinfo(title='影视资源管理系统', message='账号/密码错误请重新输入!')

def main():

# 初始化对象

L = Login()

# 进行布局

L.gui_arrang()

# 主程序执行

tkinter.mainloop()

if __name__ == '__main__':

main()

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值