Python的tkinter窗口是否有onload事件?

时间:2018-07-03 14:29:19

标签: python-3.x tkinter onload-event

当前正在学习适用于Python 3.7的tkinter模块

是否存在一个Onload()事件(类似于c#的WPF onload事件)?

在后台,我试图每秒加载一次进度条5个值直到充满,但到目前为止,我只能使用“命令”按钮来触发它,例如:

btn = Button(window, text="Click Me", command=clicked)

谢谢

这是Bryan帮助后的代码,在填充主窗口之前,进度条仍在加载:

from tkinter import Tk,Button,Frame #import *
from tkinter.ttk import Progressbar
from tkinter import ttk
import time

starttime=time.time()

def loadbar(value):
    bar['value'] += value

def clicked():
    loadbar(5)

def tick_loadingbar(event):
    if event.widget == window:
        while(bar["value"] < 100):
            loadbar(25)
            time.sleep(1)

window = Tk()
window.title("Loading Bar app")
window.geometry('350x200')
window.bind("<Map>", tick_loadingbar)
style = ttk.Style()
style.theme_use("default")
style.configure("black.Horizontal.TProgressbar", background='lightgreen')
bar = Progressbar(window, length=200, style='black.Horizontal.TProgressbar')
bar['value'] = 25
bar.grid(column=0, row=0)
btn = Button(window, text="Click Me", command=clicked)
btn.grid(column=1, row=1)

window.mainloop()

0 个答案:

没有答案