窗口循环不刷新变量值

我这个代码运行后变量on_hit循环后不变为false或者说没用进行循环

import tkinter as tk

window = tk.Tk()
window.title('测试')
window.geometry('200x100')

var = tk.StringVar()

l = tk.Label(window,
             textvariable=var,  # 标签的文字
             fg='red',
             bg='blue',  # 背景颜色
             font=('Arial', 12),  # 字体和字体大小
             width=15, height=2  # 标签长宽
             )
l.pack()  # 固定窗口位置
on_hit = False


def hit_me():
    global on_hit
    if on_hit == False:
        on_hit = True
        var.set('现在是白天')
    else:
        var.set('现在是黑天')


b = tk.Button(window, text='切换时间', width=15, height=2, command=hit_me)
b.pack()


window.mainloop()

要实现循环切换的话,在第25到第26行之间加上:
on_hit=False,重置一下即可。

def hit_me():
    global on_hit
    if on_hit == False:
        on_hit = True
        var.set('现在是白天')
    else:
        on_hit = False
        var.set('现在是黑天')

您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632