Sep-10-2023, 03:46 PM
(This post was last modified: Sep-10-2023, 03:46 PM by deanhystad.)
This does not draw the label.
Are you blocking mainloop() from running? Is there something that takes a long time to run and this prevents your window from updating? If so, that code should be run in a separate thread.
This is not the correct way to modify a label.
down_inst = Label(root, text='And Installing ' + ck_folder, font=('Arial', 15)) down_inst.place(x=150, y=450)This draws the label
root.mainloop()You can see this if you run the program below. We force the window to update after making the first label, but the second label waits for mainloop() to update the root window.
import tkinter as tk from time import sleep root = tk.Tk() tk.Label(root, text="How many labels", font=(None, 64)).pack() root.update() tk.Label(root, text="do you see?", font=(None, 64)).pack() sleep(5) root.mainloop()And before you start adding update() commands all over the place, stop and think about what you are using tkinter for. If you block mainloop() from running the window stops responding to user actions (button clicks, typing) and the window stops updating, even if you make request to change the windows appearance. Do you want your window to go dead while the program is busy. Your users will not be impressed.
Are you blocking mainloop() from running? Is there something that takes a long time to run and this prevents your window from updating? If so, that code should be run in a separate thread.
This is not the correct way to modify a label.
down_inst = Label(root, text='Downloading ' + ck_folder + ' from archive', font=('Arial', 15)) down_inst.place(x=100, y=420) root.after(5000, down_inst.destroy) # 1000=1 second shutil.copyfile(dw_source_path + dw_file_name, td_dest_path + dw_file_name) # ---- installing program ---- down_inst = Label(root, text='And Installing ' + ck_folder, font=('Arial', 15)) down_inst.place(x=150, y=450)You should hardly ever use destroy(). Make the window and labels at the start of run. To display a different message, change the label text. The example below uses a tk.StringVar to change the label text.
import tkinter as tk from time import sleep class Window(tk.Tk): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.message = tk.StringVar() label = tk.Label(self, textvariable=self.message, width=60, font=(None, 32)) label.pack(padx=10, pady=10) def display_message(self, message_list, delay=10): if message_list: self.message.set(message_list[0]) self.after(delay * 1000, self.display_message, message_list[1:], delay) else: self.message.set("") window = Window() window.display_message( ( "Twas the night before Christmas, when all through the house", "Not a creature was stirring, not even a mouse", "The stockings were hung by the chimney with care", "In hopes that St. Nicholas soon would be there", ), delay=3, ) window.mainloop()You should not use place() to set the location of a widget. Use pack() or grid(). What if you have a user that selected a larger system font? Your labels will resize, but are they correctly spaced? Using pack() or grid() lets tkinter adjust the window to fit the contents. It also lets you easily make resizable windows.