如何使我的程序仅在“ count = count + 1”而不是每次更新tkinter窗口时才更新计数器?

时间:2019-07-11 13:50:42

标签: python tkinter python-3.7

我需要用户在TKinter GUI中输入许多行。用户首先输入要输入的行数,然后输入行数。

我有一个计数器,当用户输入所有行时,该计数器会启动另一个功能,但是窗口是循环的,我不知道将计数器放在何处。

我正在运行python 3.7。我尝试将其放入read()函数中,但它会循环tkinter窗口并立即达到计数器限制。

def read():
    v2 = StringVar()
    v2.set("")
    L3 = Label(Win, textvariable=v2,fg="black",bg="light blue",font=("Agency FB", 15)).pack()
    try:
        number = e.get()
        number = int(number)
        if number <=2:
            v2.set("You need to input more than 2 lines")
        else:

            def append():
                g = b.get()
                lines = []
                lines.append(g)
                if count == number:
                    print("done")

            clearwin()
            v2 = StringVar()
            v2.set("")
            L3 = Label(Win, text = "Entering line number " + str(count) ,fg="black",bg="light blue",font=("Agency FB", 15)).pack()
            b = Entry(Win,width = "50",justify = "center",bd = "5")
            b.pack()
            b.focus_set()
            E_B = Button(Win,width = "10",command = append, height = "1", text = "Enter", fg = "black", bg = "White", font = ("Agency FB",16)).pack()
            back = Button(Win,width = "10",command = enter_rle, height = "1", text = "Back", fg = "black", bg = "White", font = ("Agency FB",16)).pack()

    except(ValueError):
        v2.set("Error")
        print("error")
clearwin()
v2 = StringVar()
v2.set("")
L3 = Label(Win, text = "Please enter number of RLE line you would like to input",fg="black",bg="light blue",font=("Agency FB", 15)).pack()
e = Entry(Win,width = "50",justify = "center",bd = "5")
e.pack()
E_B = Button(Win,width = "10",command = read, height = "1", text = "Enter", fg = "black", bg = "White", font = ("Agency FB",16)).pack()
back = Button(Win,width = "10",command = MainW, height = "1", text = "Back", fg = "black", bg = "White", font = ("Agency FB",16)).pack()
rep = Label(Win, textvariable=v2,fg="black",bg="light blue",font=("Courier", 8)).pack()
e.focus_set()

我想在计数器达到“数字”时启动另一个功能

0 个答案:

没有答案