Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Last active March 27, 2024 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vigilantPotato/7e6348fe75401b56d8cedce1f3ae1310 to your computer and use it in GitHub Desktop.
Save vigilantPotato/7e6348fe75401b56d8cedce1f3ae1310 to your computer and use it in GitHub Desktop.
Progressbar in sub-window
import ctypes
import time
import threading
import tkinter
from tkinter import ttk
class ProgressbarInSubwindow(tkinter.Toplevel):
def __init__(self, root):
super().__init__(
root,
)
self.wm_overrideredirect(True) #remove tile bar
self.geometry("+330+430")
#label on sub-window
l = tkinter.Label(
self,
text="now loading..."
)
l.pack()
#progressbar in sub-window
self.pb = ttk.Progressbar(self, mode="indeterminate")
self.pb.start(5)
self.pb.pack()
#thread
thread = threading.Thread(target=self.timer, args=(3,))
thread.start()
def timer(self, seconds): #timer
i = 0
while i < seconds:
time.sleep(1)
i += 1
self.destroy() #destroy sub-window
class ShowSubWindowButton(tkinter.Button):
def __init__(self, root):
super().__init__(
root,
text = "Start!",
command = self.show_progressbar,
)
self.pack()
def show_progressbar(self):
sub = ProgressbarInSubwindow(self) #show sub-window
if __name__ == "__main__":
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
root.geometry("+300+300")
#label
l = tkinter.Label(
root,
text="sub-window progressbar"
)
l.pack()
#button to show sub-window
sub = ShowSubWindowButton(root)
sub.pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment