Python Forum
Adding timer on the Messagebox
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Adding timer on the Messagebox
#5
Hi aniyanetworks

@woooee: I think you have placed a wrong link:
https://python-forum.io/Thread-Tkinter-K...ot-Aligned
This link has nothing to do with a count down clock.

@aniyanetworks: Here i have placed a possible variant script of a count down box. Build your own messagebox to display the count down timer. If you intend to build own GUI's you must have a closer look at Classes! To replace the ugly bitmap icon in my script pleace import your own icon image:
import tkinter as tk

APP_TITLE = "Count Down Box"
APP_XPOS = 100
APP_YPOS = 100
APP_WIDTH = 350
APP_HEIGHT = 200


class CountDownMessageBox(tk.Toplevel):
    TEXT_FONT = ('Helevtica', 12, 'bold')
    TEXT = "This process may take up to 2 min. Please try after 2min..!"
    TIMER_FONT = ('Helevtica', 16, 'bold')
    TIMER_COUNT = 10 # Seconds
    
    def __init__(self, app, msg_text=TEXT):
        self.app = app
        self.msg_text = msg_text
        
        tk.Toplevel.__init__(self, app.main_win)
        
        self.build()
        
    def build(self):
        main_frame = tk.Frame(self)
        main_frame.pack(expand=True, padx=20, pady=20)
        
        message_var = tk.StringVar(self.app.main_win, self.msg_text)
        tk.Label(main_frame, bitmap='hourglass', padx=10, font=self.TEXT_FONT,
            compound='left', textvariable=message_var, wraplength=200,
            fg='gray40').grid(row=0, column=0)
        
        self.timer_var = tk.StringVar()
        tk.Label(main_frame, textvariable=self.timer_var, font=self.TIMER_FONT,
            fg='blue').grid(row=1, column=0, padx=20, pady=20)
        
        self.count_down()
        
    def count_down(self, time_count=TIMER_COUNT):
        self.timer_var.set("{} Seconds".format(time_count))
        if time_count == 0:
            self.destroy()
            self.app.count_down_callback()
        time_count -= 1
        self.after(1000, self.count_down, time_count)
        
                    
class Application:

    def __init__(self, main_win):
        self.main_win = main_win
        
        self.count_down = False
        self.build()
        
    def build(self):
        self.main_frame = tk.Frame(self.main_win)
        self.main_frame.pack(fill='both', expand=True)

        wifiOnButton = tk.Button(self.main_win, text="WiFi-ON",
            command=self.wifiOnscript, height=1, width=22)
        wifiOnButton.pack(expand=True, padx=40, pady=10)

    def wifiOnscript(self):
        if not self.count_down:
            CountDownMessageBox(self)

    def count_down_callback(self):
        print("Count down finished!")
        
        
def main():
    main_win = tk.Tk()
    main_win.title(APP_TITLE)
    main_win.geometry("+{}+{}".format(APP_XPOS, APP_YPOS))
    #main_win.geometry("{}x{}".format(APP_WIDTH, APP_HEIGHT))

    app = Application(main_win)
    
    main_win.mainloop()
 
 
if __name__ == '__main__':
    main()
Reply


Messages In This Thread
Adding timer on the Messagebox - by aniyanetworks - Feb-11-2019, 09:06 PM
RE: Adding timer on the Messagebox - by woooee - Feb-11-2019, 09:48 PM
RE: Adding timer on the Messagebox - by woooee - Feb-12-2019, 04:45 PM
RE: Adding timer on the Messagebox - by wuf - Feb-13-2019, 10:22 AM
RE: Adding timer on the Messagebox - by woooee - Feb-13-2019, 07:39 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding the timer, smiley face, and flags in Minesweeper. javesike1262 5 3,209 May-04-2021, 10:20 PM
Last Post: deanhystad
  Tkinter messagebox and using datetime/timedelta Kaltex 3 3,352 Apr-07-2021, 06:23 PM
Last Post: Yoriz
  [Tkinter] Sound from the tkinter.messagebox tedarencn 2 5,947 Jul-11-2020, 10:45 AM
Last Post: steve_shambles
  [Tkinter] Messagebox with playsound khandelwalbhanu 6 4,395 May-16-2020, 11:40 AM
Last Post: chesschaser
  [Tkinter] messagebox is not being executed please help erwinsiuda 2 2,322 Apr-02-2020, 01:56 AM
Last Post: Larz60+
  [Tkinter] passing data to messagebox kmusawi 0 1,815 Feb-18-2019, 01:51 AM
Last Post: kmusawi
  [Tkinter] Button widget gets stuck from using tkinter.messagebox? Nwb 2 3,916 Jun-20-2018, 02:21 PM
Last Post: Nwb

Forum Jump:

User Panel Messages

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