導(dǎo)言篇:
我的python環(huán)境是:python3.6.5
這里我選擇的GUI編程包是:tkinter
tkinker在python2.5以后就是自帶包了,所以我們不需要另外安裝
tkinker相對(duì)與其他python GUI編程的包而已,是相對(duì)容易入手的
代碼篇:
#這是系統(tǒng)的登錄界面?? ?? import tkinter?? from tkinter import messagebox ?? class Login(object):?? ? ? def __init__(self):?? ? ? ? ? # 創(chuàng)建主窗口,用于容納其它組件?? ? ? ? ? self.root = tkinter.Tk()?? ? ? ? ? # 給主窗口設(shè)置標(biāo)題內(nèi)容?? ? ? ? ? self.root.title("影視資源管理系統(tǒng)(離線版)")?? ? ? ? ? self.root.geometry('450x300')?? ????????#運(yùn)行代碼時(shí)記得添加一個(gè)gif圖片文件,不然是會(huì)出錯(cuò)的 ? ? ? ? self.canvas = tkinter.Canvas(self.root, height=200, width=500)#創(chuàng)建畫布?? ? ? ? ? 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')#放置畫布(為上端)?? ?? ? ? ? ? #創(chuàng)建一個(gè)`label`名為`Account: `?? ? ? ? ? self.label_account = tkinter.Label(self.root, text='Account: ')?? ? ? ? ? #創(chuàng)建一個(gè)`label`名為`Password: `?? ? ? ? ? self.label_password = tkinter.Label(self.root, text='Password: ')?? ? ? ? ? ?? ?? ? ? ? ? # 創(chuàng)建一個(gè)賬號(hào)輸入框,并設(shè)置尺寸?? ? ? ? ? self.input_account = tkinter.Entry(self.root, width=30)?? ? ? ? ? # 創(chuàng)建一個(gè)密碼輸入框,并設(shè)置尺寸?? ? ? ? ? self.input_password = tkinter.Entry(self.root, show='*',? width=30)?? ?? ? ? ? ? # 創(chuàng)建一個(gè)登錄系統(tǒng)的按鈕?? ? ? ? ? self.login_button = tkinter.Button(self.root, command = self.backstage_interface, text = "Login", width=10)?? ? ? ? ? # 創(chuàng)建一個(gè)注冊(cè)系統(tǒng)的按鈕?? ? ? ? ? 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)?? ?? ? ? # 進(jìn)入注冊(cè)界面?? ? ? def siginUp_interface(self):?? ? ? ? ? # self.root.destroy()?? ? ? ? ? tkinter.messagebox.showinfo(title='影視資源管理系統(tǒng)', message='進(jìn)入注冊(cè)界面')?? ? ? ? ? ?? ? ? # 進(jìn)行登錄信息驗(yàn)證?? ? ? def backstage_interface(self):?? ? ? ? ? account = self.input_account.get().ljust(10," ")?? ? ? ? ? password = self.input_password.get().ljust(10," ")?? ? ? ? ? #對(duì)賬戶信息進(jìn)行驗(yàn)證,普通用戶返回user,管理員返回master,賬戶錯(cuò)誤返回noAccount,密碼錯(cuò)誤返回noPassword?? ? ? ? ? verifyResult = verifyAccount.verifyAccountData(account,password)?? ?? ? ? ? ? if verifyResult=='master':?? ? ? ? ? ? ? self.root.destroy()?? ? ? ? ? ? ? tkinter.messagebox.showinfo(title='影視資源管理系統(tǒng)', message='進(jìn)入管理界面')?? ? ? ? ? elif verifyResult=='user':?? ? ? ? ? ? ? self.root.destroy()?? ? ? ? ? ? ? tkinter.messagebox.showinfo(title='影視資源管理系統(tǒng)', message='進(jìn)入用戶界面')? ? ? ? ? ? elif verifyResult=='noAccount':?? ? ? ? ? ? ? tkinter.messagebox.showinfo(title='影視資源管理系統(tǒng)', message='該賬號(hào)不存在請(qǐng)重新輸入!')?? ? ? ? ? elif verifyResult=='noPassword':?? ? ? ? ? ? ? tkinter.messagebox.showinfo(title='影視資源管理系統(tǒng)', message='賬號(hào)/密碼錯(cuò)誤請(qǐng)重新輸入!')?? ?? def main():?? ? ? # 初始化對(duì)象?? ? ? L = Login()?? ? ? # 進(jìn)行布局?? ? ? L.gui_arrang()?? ? ? # 主程序執(zhí)行?? ? ? tkinter.mainloop()?? ?? ?? if __name__ == '__main__':?? ? ? main()
效果篇:
語(yǔ)法介紹:環(huán)境配置:
Python3.6.5, 前往官網(wǎng)下載
tkinker包:Python2.5之后,tkinker包是自帶的,我們直接導(dǎo)入就好了
基本語(yǔ)法:
self.root = tkinter.Tk()
創(chuàng)建一個(gè)窗口對(duì)象root,root前面的self.是面向?qū)ο罄锩娴膬?nèi)容,不明白的童鞋可以去Google一下面向?qū)ο?
self.root.title("影視資源管理系統(tǒng)(離線版)") self.root.geometry('450x300')
給窗口root設(shè)置標(biāo)題,并設(shè)置窗口
self.canvas = tkinter.Canvas(self.root, height=200, width=500)#創(chuàng)建畫布 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')#放置畫布(為上端)
如果我們需要讓自己的界面在美觀上加分,大可以試試創(chuàng)建一個(gè)畫布,也就是下面這個(gè)東西
我這里是先對(duì)圖片背景進(jìn)行了透明化處理,需要的小伙伴可以去 這里? 對(duì)圖片進(jìn)行處理,個(gè)人覺(jué)得這個(gè)網(wǎng)站還是不錯(cuò)的
#創(chuàng)建一個(gè)`label`名為`Account: ` self.label_account = tkinter.Label(self.root, text='Account: ') #創(chuàng)建一個(gè)`label`名為`Password: ` self.label_password = tkinter.Label(self.root, text='Password: ')
這里創(chuàng)建的是一個(gè)label,label是什么不明白可以參考上面貼圖的“Account:”與“Password:”
.Label(A, B):參數(shù)A代表Lable依賴窗口,參數(shù)B即用戶可見的Lable的名字了(text="LableName")
.Button(A, B, text='', [width='', height='']):參數(shù)A是按鈕依賴的窗口主體,參數(shù)B是按鈕的相應(yīng)事件(command = self.siginUp_interface)這里的響應(yīng)事件的進(jìn)行注冊(cè)/登錄進(jìn)入后臺(tái),command后接響應(yīng)函數(shù)。
.Entry(A):輸入框,參照前面的.Label(),有疑問(wèn)的可以在下方留言
.place(x="", y=""):這個(gè)是設(shè)置窗口部件的函數(shù)
額。。。。登錄界面就介紹到這里了,后面我會(huì)繼續(xù)更新登錄界面的響應(yīng)機(jī)制,有不明的地方可以在下方留言,我看到會(huì)回復(fù)的
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺(jué)我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對(duì)您有幫助就好】元
