0

I'm working on a project and when starting my program for the first time I want it to download some extra files, which were not incluided when it was getting installed. I want tkinter to show a window, telling the user what is going on and telling them what it is working on. It would be usefull for the window to be unclosable, and gets destroyed when the downloading is done. I'm not all too familiar with Tkinter, so the tk code is scrambeled together from a few websites. I'm using TK because I also need tk for a file picking dialog, and including pygame seems a bit exessive as a third GUI library (eel/tkinter/pygame).

The current (sample) code looks like this:

import tkinter as tk
import time

def donothing():
    return
main = tk.Tk()
current_dependency = tk.StringVar()
current_dependency.set('Loading...')

main.geometry("500x170")
tk.Label(main, text= "Toolbox is\ndownloading dependencies...", font=('Helvetica 18 bold')).pack(pady=20)
tk.Label(main, textvariable = current_dependency, font=('Helvetica 16')).pack()

main.protocol('WM_DELETE_WINDOW',donothing) ## UNCLOSEABLE


def on_startup():
    # Resolving dependencies
    for exe in ('./ffmpeg/ffmpeg64.exe', './ffmpeg/ffprobe64.exe'):
        # Running the code beneath, assuming the files are not present.
        current_dependency.set(exe)
        time.sleep(2)
        main.mainloop()

if __name__ == '__main__':
    on_startup()

time.sleep(2) is a stand-in for the function that downloads the current dependency

(please respond with python 3)

user15055153
  • 25
  • 1
  • 5
  • Does this answer your question? [How to run a function in the background of tkinter](https://stackoverflow.com/questions/5048082/how-to-run-a-function-in-the-background-of-tkinter) – Tim Aug 02 '22 at 21:30
  • You would need to run the code in a background thread, and send the status to a variable that you're reading in an `after` loop. Background threads can't touch the UI. – Tim Roberts Aug 02 '22 at 21:31
  • Kind of, but how would that work on a list, instead of on a loop? There is an end to my function. – user15055153 Aug 02 '22 at 21:33
  • You shouldn't ever need to call `mainloop` more than once. – Bryan Oakley Aug 02 '22 at 21:57

1 Answers1

0

To open a window you can simply call tk.Tk() again.

def createNewWindow():
   main2 = tk.Tk()

   (Once finished loading) -> destoryMain2()
   def destoryMain2():
      main2.destory()

   main2.mainloop()
  • This does not work. The window only appears when the download is complete. The idea is that the user sees that something is down(loading). Additionally, it would be nice if the window closes when the download is complete. – user15055153 Aug 03 '22 at 10:43