Advertisement
Uno-Dan

The fix

Nov 18th, 2019
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1.  
  2. import tkinter as tk
  3. import tkinter.ttk as ttk
  4.  
  5. import time
  6.  
  7.  
  8. class App(tk.Tk):
  9.     def __init__(self):
  10.         super().__init__()
  11.         self.rowconfigure(990, weight=1)
  12.         self.columnconfigure(0, weight=1)
  13.         self.title('Timed Events Demo')
  14.         self.geometry('420x200+20+20')
  15.  
  16.         var = tk.StringVar()
  17.  
  18.         tk_spn = tk.Spinbox(
  19.             self,
  20.             value=0,
  21.             from_=0, to=1000,
  22.             values=list(range(0, 1000))
  23.         )
  24.         tk_spn.grid(row=0, pady=5)
  25.  
  26.         ttk_spn = ttk.Spinbox(
  27.             self,
  28.             from_=0, to=1000,
  29.             value=0,
  30.             values=list(range(0, 1000))
  31.         )
  32.         ttk_spn.grid(row=1, pady=5)
  33.  
  34.         self.t1 = round(time.monotonic() * 1000)
  35.  
  36.         def do_work(e):
  37.             wdg = e.widget
  38.             old_val = wdg.get()
  39.  
  40.             def func():
  41.                 t2 = round(time.monotonic() * 1000)
  42.                 if t2 - self.t1 < 500:
  43.                     e.widget.set(old_val)
  44.                     return
  45.                 self.t1 = round(time.monotonic() * 1000)
  46.             self.after(0, func)
  47.  
  48.         tk_spn.bind('<<Increment>>', do_work)
  49.         tk_spn.bind('<<Decrement>>', do_work)
  50.  
  51.         ttk_spn.bind('<<Increment>>', do_work)
  52.         ttk_spn.bind('<<Decrement>>', do_work)
  53.  
  54.  
  55. def main():
  56.     app = App()
  57.     app.mainloop()
  58.  
  59.  
  60. if __name__ == '__main__':
  61.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement