tkinter做一個簡單的登陸頁面(十六)

Tynam.Yang發表於2018-04-13

做一個簡單的登陸頁面

 1 import tkinter
 2 
 3 wuya = tkinter.Tk()
 4 wuya.title("wuya")
 5 wuya.geometry("900x380+300+150")
 6 
 7 
 8 # add image
 9 pic = r'/Users/ydj/Desktop/未命名資料夾/bg.gif'
10 canvas = tkinter.Canvas(wuya)
11 image_file = tkinter.PhotoImage(file=pic)
12 image = canvas.create_image(0,0,anchor='nw',image=image_file)
13 canvas.place(x=0,y=0,height=360, width=619)
14 
15 # add lable_title
16 lp_title = tkinter.Label(wuya,text='舞涯管理系統',font=("Arial Black",22),fg='#32cd99')
17 lp_title.place(x=625,y=150)
18 
19 # add copyright_lable
20 copyright_lable = tkinter.Label(wuya,text='wuya @ copyright')
21 copyright_lable.pack(side='bottom')
22 
23 # add name
24 name_text = tkinter.Variable()
25 name_lb = tkinter.Label(wuya,text='使用者名稱:',font=('微軟雅黑',13))
26 name_lb.place(x=625,y=200)
27 name_input = tkinter.Entry(wuya,textvariable=name_text,width=20)
28 name_input.place(x=685,y=200)
29 
30 # add password
31 pwd_text = tkinter.Variable()
32 pwd_lb = tkinter.Label(wuya,text='密碼:',font=('微軟雅黑',13))
33 pwd_lb.place(x=625,y=235)
34 pwd_input = tkinter.Entry(wuya,width=20,textvariable=pwd_text)
35 pwd_input.place(x=685,y=235)
36 
37 
38 # username  and password is real
39 def login_func():
40     if name_text.get() == "":
41         msg = "使用者名稱不能為空"
42     elif pwd_text.get() == "":
43         msg = "密碼不能為空"
44     elif pwd_text.get()!="" and name_text.get()!="":
45         msg = "登陸成功"
46     else:
47         msg = ""
48     pwd_lb = tkinter.Label(wuya,text=msg,font=('微軟雅黑',11),fg='red')
49     pwd_lb.place(x=685, y=265)
50 
51 
52 # add login_button
53 login_button = tkinter.Button(wuya,text='登陸',font=('微軟雅黑',12),command=login_func)
54 login_button.place(x=770,y=280)
55 
56 # add quit_button
57 quit_button = tkinter.Button(wuya,text='退出',font=('微軟雅黑',12),command=wuya.quit)
58 quit_button.place(x=700,y=280)
59 
60 wuya.mainloop()

結果:

相關文章