Python Forum
[Tkinter] Please Wait window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Please Wait window
#1
hi, sorry again for my bad English,
I like to create "loading, please wait... " window
but somehow the windows do not appear, this is the code

import threading
import time
from tkinter import *
done = False
#here is the animation
def PW():
    """
    NW = Toplevel(root)
    NW.title("Loading")
    NW.geometry("200x200")
    NWLabel(NW,text ="Please wait").pack()
    """
    x = 0
    global done
    while not done:
        x = x + 1
        print(x)# just for tracking if program is running
        time.sleep(0.1)
    """
    NW.destroy()
    """


def starting():
    t = threading.Thread(target=PW)
    t.start()
    #long process start
    time.sleep(10)
    #long process stop
    global done
    done = True

root = Tk()
root.geometry("300x100")
root.title("unstart")
btn = Button(root, text ="Click", command = starting)
btn.grid()
mainloop()
note : I put some comments in the code that I hope someone in here will edit,
I will appreciate any clue, link, or working code,
thank you, have a nice day
Reply
#2
Maybe this will get you started:
#! /usr/bin/env python3

import tkinter as tk

root = tk.Tk()
root['padx'] = 5
root['pady'] = 4

def update(win, label):
    # Set up a counter variable
    update.counter = getattr(update, 'counter', 5)
    # Display some text
    label['text'] = f'Window will close in {update.counter} seconds'
    # Decrease the counter
    update.counter -= 1
    # Call self every one second
    win.after(1000, update, win, label)
    # If the counter reaches 0, destroy the toplevel window
    if update.counter == 0:
        # Reset counter
        update.counter = 5
        win.destroy()


def new_window():
    # Create a toplevel window
    window = tk.Toplevel(None)
    win_label = tk.Label(window)
    win_label['text'] = f'Window will close in 5 seconds'
    win_label.pack()
    # Call the update function
    update(window,win_label)



label = tk.Label(root, text='Default label text')
label.pack(side = 'top')
# Button with command to call new window
btn = tk.Button(root, text='Click', command=new_window)
btn.pack()

root.mainloop()
kucingkembar likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
@menator01 I appreciate your reply, but this is not looking for,

the "Loading, please wait" window appears when the program is really loading,
I don't know when the loading is really done, it can be 5 seconds, 10 seconds, 20 seconds,
that is why I use:
    
t = threading.Thread(target=PW)
t.start()
and I get this code from here
Print a message for user while long process running in Python

thank you for the reply, but this not I looking for,
but I will give you reputation point and like for the program
Reply
#4
The counter was just an example. Do the threading and when finished close the window
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#5
after i do some experiments, the code is work as I intended,
thank you
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 599 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,779 Nov-02-2019, 12:18 PM
Last Post: 1885
  update a variable in parent window after closing its toplevel window gray 5 9,161 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020