Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Adding timer on the Messagebox
#1
Hello Experts,
I would like to show some message on the Message Box, with a Timer on it. Messagebox will have 2 min countdown clock and after 2 min it will be close.

My code is here:
from tkinter import *
from tkinter import messagebox
window= Tk()

def wifiOnscript():
    messagebox.showinfo("Information!!", "This process may take up to 2 min. Please try after 2min...")

wifiOnButton=Button(window,text="WiFi-ON",command=wifiOnscript, height=1, width=22)
wifiOnButton.grid(row=2,column=0,padx=40, pady=10)

window.mainloop()

Please let me know how can I add the clock to my message box.
Thanks in advance.
Quote
#2
See my post on adding a timer towards the bottom of this thread https://python-forum.io/Thread-Tkinter-K...ot-Aligned Note that the timer is independent of the widget being displayed.
Quote
#3
(Feb-11-2019, 09:48 PM)woooee Wrote: See my post on adding a timer towards the bottom of this thread https://python-forum.io/Thread-Tkinter-K...ot-Aligned Note that the timer is independent of the widget being displayed.


Hello Woooee,
I am a newbie in Python and your scripts look a like science language to me, I am not getting anything sorry.
Quote
#4
That is the only way to do it that I know of. "I am not getting anything" is too vague for any response. What have you tried and what do you understand and what do you not understand?
Quote
#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()
Quote
#6
>@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.

True as the link you posted goes nowhere. The link that I posted above is correct and the code at that location can be run and shows a countdown timer.
Quote
#7
(Feb-13-2019, 07:39 PM)woooee Wrote: >@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.

True as the link you posted goes nowhere. The link that I posted above is correct and the code at that location can be run and shows a countdown timer.

Thanks, guys for your kind time and help.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  [Tkinter] Adding space between Notebook tabs Columbo 4 278 Jul-10-2019, 10:46 PM
Last Post: Columbo
  [WxPython] Adding a Window to a Button wxPython ShashankDS 4 344 Apr-23-2019, 06:53 PM
Last Post: Yoriz
  tkinter- adding a new window after clicking a button built on the gui ShashankDS 2 320 Apr-18-2019, 12:48 PM
Last Post: ShashankDS
  [Tkinter] passing data to messagebox kmusawi 0 217 Feb-18-2019, 01:51 AM
Last Post: kmusawi
  [Tkinter] Adding New TAB to NoteBook Widget by Clicking Vicolas 0 299 Feb-15-2019, 06:03 PM
Last Post: Vicolas
  Adding Progressbar to button aniyanetworks 9 1,085 Feb-07-2019, 11:12 AM
Last Post: Larz60+
  [Tkinter] Adding graphics to canvas vangphucthinh 0 280 Jan-24-2019, 04:58 PM
Last Post: vangphucthinh
  Need help adding a sql List to a combo box PyQt5 jimmyvegas29 1 1,639 Jul-20-2018, 07:28 AM
Last Post: Alfalfa
  [Tkinter] Button widget gets stuck from using tkinter.messagebox? Nwb 2 974 Jun-20-2018, 02:21 PM
Last Post: Nwb
  [Tkinter] Adding a Frame litaboss 2 842 Mar-02-2018, 06:04 AM
Last Post: litaboss

Forum Jump:


Users browsing this thread: 1 Guest(s)