Python教程 - Tkinter 登陆界面示例


import tkinter
import tkinter.messagebox
import random

bingo = random.randint(1,100)

def btn_click():
    if e1.get()=='xiaoming' and e2.get()=='123456':
        tkinter.messagebox.showinfo('tips', 'Correct')
    else:
        tkinter.messagebox.showerror('tips', 'Error')

main = tkinter.Tk()
main.title('Hello tkinter')
main.geometry('300x200')

l1 = tkinter.Label(main, text='User name:')
l1.config(height=2)
l1.config(width=20)
l1.pack()

e1 = tkinter.Entry(main)
e1.pack()

l2 = tkinter.Label(main, text='Password:')
l2.config(height=2)
l2.config(width=20)
l2.pack()

e2 = tkinter.Entry(main)
e2.pack()

b = tkinter.Button(main,text='OK')
b.config(bg='green')
b.config(command=btn_click)
b.pack()

main.mainloop()