python - 如何在 Tkinter 中使用带有 root.after() 的嵌套函数?
问题描述
我正在尝试在以下代码中Tkinter
使用嵌套函数:.after()
from tkinter import *
a=0
def fct1() :
global a
global b
b=0
text = Label(root, text="Hey!")
text.pack()
def fct2() :
global b
text2 = Label(root, text="Yes")
text2.pack()
b+=1
if b>3 :
return
root.after(5,fct2)
fct2()
a+=1
if a>5 :
return
root.after(25,fct1)
root = Tk()
fct1()
root.mainloop()
使用此代码,我想显示一个“嘿!” 在我的 Tkinter 根目录中,然后运行函数fct2将显示 4“是”,然后再执行 5 次。
但是当我运行代码时,6“嘿!” 按预期显示,但在每一个中,我们看到显示的“是”的数量看起来是随机的,而每次应该是 4。有谁知道我为什么会遇到这个问题?
解决方案
推荐阅读
- java - Java有时在读取文件时返回空字符串
- finance - *TradingView Pine* 止盈警报不起作用
- apache - 您可以将“/.html”的请求准确地重定向到 index.html 吗?
- java - 如何计算我的程序中的年差?
- traefik - Traefik - 重定向和斜杠
- maxima - 如何告诉 Maxima 使用更多内存?
- python - python scipy内置函数ODEINT使用不同的时间点集(参数t)
- python - 在熊猫中按日期对前 n 个值进行分组
- flash - 我需要 ATtiny1617 的引导加载程序吗
- php - Ajax 请求发送 CURL 请求