2

Currently learning the tkinter module for Python 3.7

Is there an Onload() event (kind of like the c#'s WPF onload event)?

The background, I am trying to load a progress bar 5 values every second till full, but so far I can only trigger this using the button "command" eg:

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

Thanks,

Here is my code after Bryan's help, the progress bar is still loading before the main window is populated:

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()
8WmK
  • 106
  • 1
  • 8

1 Answers1

0

There might be a solution. You could update your window with the update() method and do the onload code. After that you mainloop the window. That worked for me.

JL710
  • 85
  • 1
  • 5