Tkinter load screen with updating labels

Tkinter load screen with updating labels

I am writing an application which involves a fair amount of data munging at launch. What I'd like to do is create a splash screen that tells the user what stage of the data loading process is happening in real time.

I am writing an application which involves a fair amount of data munging at launch. What I'd like to do is create a splash screen that tells the user what stage of the data loading process is happening in real time.

My plan was to create a Label and pass new text to that Label depending on what calculations were going on in that moment. However in my various attempts the best I've done is get the labels to show up only after the munging is complete.

I saw this, which helped me a bit, but still not getting all the way there: Tkinter Show splash screen and hide main screen until __init__ has finished

Below is my current best attempt (taking all the actual dataframe stuff out to make it minimally executable)

[EDIT TO ADD] Ideally I'd like to do this in a way that doesn't require all the data munging to occur inside the class. IOW, phase 1 launches the splash screen, phase 2 runs the data munging in the main code, phase 3 launches the primary UI

import time
from tkinter import *

class LoadScreen(Toplevel): def init(self, parent): Toplevel.init(self, parent) self.title('Loading') self.update()

class UserInterface(Tk): def init(self, parent): Tk.init(self, parent) self.parent=parent self.withdraw() loader = LoadScreen(self) self.load_label = Label(loader, text='Loading') self.load_label.grid(row=0, column=0, padx=20, pady=20) self.stage_label = Label(loader, text='Preparing dataframe') self.stage_label.grid(row=1, column=0, padx=20, pady=20) #loader.destroy() self.main_screen()

def main_screen(self):
    self.deiconify()
    self.load_label = Label(self, text='Done')
    self.load_label.grid(row=0, column=0, padx=20, pady=20)
    self.close_button = Button(self, text='Close', 
        command = lambda: self.destroy())
    self.close_button.grid(row=1, column=0, padx=20, pady=20)

ui = UserInterface(None)

#Pretend I'm doing some dataframe munging print('1') time.sleep(2) ui.stage_label['text'] = 'Running some calculations' print('2') time.sleep(2) ui.stage_label['text'] = 'Finishing up' print('3') time.sleep(2)

ui.mainloop()


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

Top Python Development Companies | Hire Python Developers

After analyzing clients and market requirements, TopDevelopers has come up with the list of the best Python service providers. These top-rated Python developers are widely appreciated for their professionalism in handling diverse projects. When...

Python GUI Programming Projects using Tkinter and Python 3

Python GUI Programming Projects using Tkinter and Python 3

Guide to Python Programming Language

Guide to Python Programming Language