Python GUI-标签并终止

时间:2015-05-03 19:01:23

标签: python tkinter

此程序将要求输入用户名和密码。你有3次尝试 我想让这个节目在显示“再见”之后结束5 SEC。并且'感谢您使用.....'如果我输入错误的密码3次,但我该怎么做?

import Tkinter


def win1():
    global root
    global tries
    # this is the main/root window
    root = Tkinter.Tk()
    root.title("Stock Plus system")
    root.geometry('400x150')
    b2Var=Tkinter.StringVar()
    tries = 1

def win2():
    # this is the child window

    board = Tkinter.Toplevel()
    board.title("Window 2")
    s1Var = Tkinter.StringVar()
    s2Var = Tkinter.StringVar()

    square1Label = Tkinter.Label(board,textvariable=s1Var)
    square1Label.grid(row=0, column=7)
    square2Label = Tkinter.Label(board,textvariable=s2Var)
    square2Label.grid(row=0, column=6)

def textboxvalue():
    global tries

    if (tries!=3 ):
       textvalue=b2Var.get()
       if textvalue ==('stock123'):
           label4=Tkinter.Label(root,text='Welcome to stock plus system, press login again to start using')
           label4.grid(row=3,column=1)
           Button_1 = Tkinter.Button(root, text="Login", command=win2)
           Button_1.grid(row=2,column=1)

       else:
           tries =tries+1
           label3=Tkinter.Label(root,text='Try again')
           label3.grid(row=3,column=1)

    else:
        label5=Tkinter.Label(root,text='bye')
        label5.grid(row=4,column=1)
        label6=Tkinter.Label(root,text='Thank You for using Stock Plus System ')
        label6.grid(row=5,column=1)





win1()
Button_1 = Tkinter.Button(root, text="Login", command=textboxvalue)
Button_1.grid(row=2, column=1)
b1Var = Tkinter.StringVar()
b2Var = Tkinter.StringVar()

box1Label = Tkinter.Label(root,text='Username:')
box1Label.grid(row=0)
box2Label = Tkinter.Label(root,text='Password:')
box2Label.grid(row=1)
box1Text = Tkinter.Entry(root,textvariable=b1Var,width=12)
box1Text.grid(row=0, column=1)
box2Text = Tkinter.Entry(root,textvariable=b2Var,width=12)
box2Text.grid(row=1, column=1)

root.mainloop()

1 个答案:

答案 0 :(得分:1)

您可以尝试在任何Tkinter小部件上使用.after()方法..

来自here

  

警报处理程序和其他非事件回调

id = w.after(time, callback) 
id = w.after_idle(callback) 
w.after_cancel(id)

例如,试试这个:

import sys

def app_exit():
    return sys.exit()

...
# at the relevant spot in your code
label6=Tkinter.Label(root,text='Thank You for using Stock Plus System ')
label6.after(5000, app_exit)
label6.grid(row=5,column=1)