Python Forum
[Tkinter] RE: status bar to return to the centre after 1 minute of clicking a button ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] RE: status bar to return to the centre after 1 minute of clicking a button ?
#7
Added the code to reset the status bar to the original function code post
import tkinter as tk
import tkinter.ttk as ttk

root = tk.Tk()

process = tk.IntVar(value=5)
root.after_id = None
progressbar = ttk.Progressbar(root, length=200, maximum=10, variable=process)
progressbar.grid(row=1)


def reset_water():
    process.set(5)
    root.after_id = None


def reset_after(delay_ms):
    if root.after_id:
        root.after_cancel(root.after_id)

    root.after_id = root.after(delay_ms, reset_water)


def add_water():
    progress_value = process.get()
    if progress_value < progressbar["maximum"]:
        process.set(progress_value + 1)
        reset_after(60000)


def sub_water():
    progress_value = process.get()
    if progress_value > 0:
        process.set(progress_value - 1)
        reset_after(60000)


add = ttk.Button(root, text="Water +", command=add_water)
sub = ttk.Button(root, text="Water -", command=sub_water)

label = ttk.Label(root, textvariable=process)

label.grid(row=0)
add.grid(row=0, sticky="e")
sub.grid(row=0, sticky="w")

root.mainloop()
Reply


Messages In This Thread
RE: RE: status bar to return to the centre after 1 minute of clicking a button ? - by Yoriz - May-27-2019, 04:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Clicking on the button crashes the TK window ODOshmockenberg 1 2,200 Mar-10-2022, 05:18 PM
Last Post: deanhystad
  adding button status updates to countdown counter knoxvilles_joker 7 3,342 Apr-18-2021, 01:59 AM
Last Post: knoxvilles_joker
  [Tkinter] showing return from button on main screen blazejwiecha 4 2,595 Nov-22-2020, 04:33 PM
Last Post: blazejwiecha
  Need tkinter help with clicking buttons pythonprogrammer 2 2,402 Jan-03-2020, 04:43 AM
Last Post: joe_momma
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,951 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  tkinter- adding a new window after clicking a button built on the gui ShashankDS 2 6,552 Apr-18-2019, 12:48 PM
Last Post: ShashankDS
  [Tkinter] Adding New TAB to NoteBook Widget by Clicking Vicolas 0 2,583 Feb-15-2019, 06:03 PM
Last Post: Vicolas
  [Tkinter] Clicking a RadioButton in a for Loop & Getting the Appropriate Return Vicolas 1 5,103 Feb-02-2019, 01:53 AM
Last Post: woooee
  [Tkinter] How to get & delete details from each input by clicking a button Vicolas 6 3,782 Feb-01-2019, 11:00 AM
Last Post: Vicolas
  [PyQt] No reaction and no error message when clicking button Atalanttore 4 4,755 Nov-23-2018, 01:48 PM
Last Post: Atalanttore

Forum Jump:

User Panel Messages

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