python - tkinter 标签不适用于 if
问题描述
我有这个代码:
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()
问题出在text2
我做if的时候。输出必须是一个回归计时器,从 开始spin4
,但text2
不要改变。
我试着写一个ìnt
,if text2 == 0:
但无论如何都行不通。我尝试更改if
并且仅更改text2
输出,例如:
if text2 == 0:
text2(text='Hi!')
但是输出是一样的:0
解决方案
if text2 == 0:
text2.config(text="Hi!")
推荐阅读
- android - 如何从 Widget 传递数据并打开 Activity?
- linux - 如何在卷曲字符串中使用公历时间戳
- java - 在时区的日期时间不明确的情况下抛出异常?
- angular - 为什么Angular Material源代码中的这一行有`|| 空`?
- xamarin - Xamarin.Forms:网格单元格可以包含多个标签吗?
- android - 如何禁用使用 Flutter 1.0 在 Google 地图中点击标记时出现的导航按钮?
- c# - 编译器错误消息:CS1513:} 预期如果是瀑布
- android - 当应用程序处于后台时,活动和片段会发生什么
- angular - 为什么我在写第一个字母时会失去输入的焦点?
- notepad++ - 如何删除notepd ++中的特定行