tkinter标签不适用于if

问题描述 投票:0回答:1

我有此代码:

def timer():
text2['text'] = str(timer.current)
timer.current = timer.current - 1
if timer.current >= 0:
    f.after(1000, timer)
def codigo():
    global text2
    f2=Frame(f, width=300, height=500)
    f2.pack()
    f2.config(bg='dark grey')
    text2=Label(f, text=spin.get(), font=('Arial Bold', 90), bg=('dark grey'))
    text2.place(x=80, y=200)
    timer.current = int(spin.get())
    timer()

    text3=Label(f, text = int(spin4.get()), font=('Arial Bold', 30), bg=('dark grey'))
    text3.place(x=200, y=350)
    text4=Label(f, text=spin4.get(), font=('Arial Bold', 30), bg=('dark grey'))
    text4.place(x=170, y=400)
    text5=Label(f, text='Ejercicios:', font=('Arial Bold', 30), bg=('dark grey'))
    text5.place(x=5, y=350)
    text6=Label(f, text='Rondas:', font=('Arial Bold', 30), bg=('dark grey'))
    text6.place(x=5, y=400)
    def ejercicio():
        #here is the problem, I think
        if text2 == 0:
            text2(text=spin4.get())
            timer.current(int(spin4.get()))
btn1 = tk.Button(f, text='Empezar', command=codigo, bg=('dark grey'))
btn1.pack()
btn1.place(x=150, y=150)
window.mainloop()

当我执行if时,问题出在text2中。输出必须是从spin4开始的回归计时器,但text2不变。

我试图在ìnt上写一个if text2 == 0:,但无论如何都行不通。我试图更改if,仅更改text2输出,例如:

if text2 == 0:
    text2(text='Hi!')

但是输出是相同的:0

python python-3.x user-interface tkinter label
1个回答
0
投票
if text2 == 0:
    text2.config(text="Hi!")
© www.soinside.com 2019 - 2024. All rights reserved.