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()


python

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Basic Data Types in Python | Python Web Development For Beginners

In the programming world, Data types play an important role. Each Variable is stored in different data types and responsible for various functions. Python had two different objects, and They are mutable and immutable objects.

How To Compare Tesla and Ford Company By Using Magic Methods in Python

Magic Methods are the special methods which gives us the ability to access built in syntactical features such as ‘<’, ‘>’, ‘==’, ‘+’ etc.. You must have worked with such methods without knowing them to be as magic methods. Magic methods can be identified with their names which start with __ and ends with __ like __init__, __call__, __str__ etc. These methods are also called Dunder Methods, because of their name starting and ending with Double Underscore (Dunder).

Python Programming: A Beginner’s Guide

Python is an interpreted, high-level, powerful general-purpose programming language. You may ask, Python’s a snake right? and Why is this programming language named after it?

Hire Python Developers

Are you looking for experienced, reliable, and qualified Python developers? If yes, you have reached the right place. At **[HourlyDeveloper.io](https://hourlydeveloper.io/ "HourlyDeveloper.io")**, our full-stack Python development services...

Python any: How to Check If Element is Iterable or Not

Python any() function returns True if any element of an iterable is True otherwise any() function returns False. The syntax is any().