famansour

Tracker tempo

Oct 19th, 2020
332
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 13.63 KB | None | 0 0
  1. import tkinter as tk
  2. # from mttkinter import mtTkinter as tk
  3. import time
  4. # import classes
  5. # import win32api
  6. # from threading import Thread
  7. import sys
  8. class Fullscreen_Example:
  9.     def __init__(self):
  10.         self.window = tk.Tk()
  11.         self.window.attributes('-fullscreen', True)  
  12.         self.fullScreenState = False
  13.         self.window.bind("<F11>", self.toggleFullScreen)
  14.         self.window.bind('<ButtonRelease-2>', self.quitFullScreen)
  15.         self.window.mainloop()
  16.        
  17.         # LabelEff = tk.Label(self, textvariable='AAAAAAAA')
  18.         # LabelEff.pack()
  19.     def toggleFullScreen(self, event):
  20.         self.fullScreenState = not self.fullScreenState
  21.         self.window.attributes("-fullscreen", self.fullScreenState)
  22.         # LabelEff = tk.Label(self.window, textvariable='AAAAAAAA')
  23.         LabelEff.pack()
  24.         # LabelEff.pack()
  25.         StopWatch1._Label1.pack()
  26.         # StopWatch2._Label1.pack()
  27.         # root = Tk()
  28.         var = tk.StringVar()
  29.         label = Label( self.window, textvariable=var, relief=RAISED )
  30.  
  31.         var.set("Hey!? How are you doing?")
  32.         label.pack()
  33.         self.window.mainloop()
  34.     def quitFullScreen(self, event):
  35.         # self.fullScreenState = False
  36.         # self.window.attributes("-fullscreen", self.fullScreenState)
  37.         self.window.bind('<ButtonRelease-2>', self.window.destroy())
  38.  
  39.     # var = tk.StringVar()
  40.     # label = Label( self.window, textvariable=var, relief=RAISED )
  41.  
  42.     # var.set("Hey!? How are you doing?")
  43.     # label.pack()
  44.     # self.window.mainloop()
  45.  
  46. class WindowDraggable():
  47.  
  48.     def __init__(self, root):
  49.         self.root = root
  50.         root.bind('<ButtonPress-2>', self.StartMove)
  51.         root.bind('<ButtonRelease-2>', self.StopMove)
  52.         root.bind('<B2-Motion>', self.OnMotion)
  53.  
  54.     def StartMove(self, event):
  55.         self.x = event.x
  56.         self.y = event.y
  57.  
  58.     def StopMove(self, event):
  59.         self.x = None
  60.         self.y = None
  61.  
  62.     def OnMotion(self,event):
  63.         x = (event.x_root - self.x - self.root.winfo_rootx() + self.root.winfo_rootx())
  64.         y = (event.y_root - self.y - self.root.winfo_rooty() + self.root.winfo_rooty())
  65.         root.geometry("+%s+%s" % (x, y))
  66.        
  67.        
  68. class StopWatch(tk.Frame):  #Class StopWatch inheriting from the Tkinter class Frame
  69.     """ Implements a stop watch frame widget. """                                                                
  70.     def __init__(self, parent=None, **kw):        
  71.         tk.Frame.__init__(self, parent, kw)
  72.         # self.configure(bg='black')
  73.         self._start = 0.0        
  74.         self._elapsedtime = 0.0
  75.         self.timestr = tk.StringVar()              
  76.         self._running = 0
  77.        
  78.         self._Label1 = tk.Label(self, textvariable=self.timestr)
  79.         self._setTime(self._elapsedtime)
  80.         self._Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  81.  
  82.        
  83.    
  84.     # def makeWidgets(self):                        
  85.         # """ Make the time label. """
  86.         # l = tk.Label(self, textvariable=self.timestr)
  87.         # self._setTime(self._elapsedtime)
  88.         # l.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  89.         # l.configure(bg='white')        
  90.         # return l  
  91.        
  92.     def _update(self):
  93.         """ Update the label with elapsed time. """
  94.         self._elapsedtime = time.time() - self._start
  95.         self._setTime(self._elapsedtime)
  96.         self._timer = self.after(50, self._update)
  97.         # print (self._timer, '= self.after')
  98.     def _setTime(self, elap):
  99.         """ Set the time string to Minutes:Seconds:Hundreths """
  100.         hours = int(elap/(60.0*60.0))
  101.         minutes = int((elap- hours*60.0*60.0)/60.0)
  102.         seconds = int(elap- hours*60.0*60.0 - minutes*60.0)
  103.         # hseconds = int((elap - minutes*60.0 - seconds)*100)                        
  104.         self.timestr.set('%02d:%02d:%02d' % (hours, minutes, seconds)) # convert date and time and datetime objects to its equivalent string
  105.         # print(('%02d:%02d:%02d' % (minutes, seconds, hseconds)))
  106.        
  107.     def Start(self):          
  108.         if not self._running:  
  109.             self._start = time.time() - self._elapsedtime
  110.             self._update()
  111.             self._running = 1
  112.     def Stop(self):
  113.         if self._running:
  114.             self.after_cancel(self._timer)            
  115.             self._elapsedtime = time.time() - self._start    
  116.             self._setTime(self._elapsedtime)
  117.             self._running = 0
  118.             # print(self._elapsedtime)
  119.             # print ('after_cancel(', self._timer, ')')
  120.  
  121.  
  122.     def Reset(self):                                  
  123.         """ Reset the stopwatch. """
  124.         self._start = time.time()        
  125.         self._elapsedtime = 0.0    
  126.         self._setTime(self._elapsedtime)
  127.    # if not StopWatch1Local._running:
  128. def mouse1Clicked():
  129.     global StopWatch1
  130.     global StopWatch2
  131.     # StopWatch1._Label1.pack_forget()
  132.     # StopWatch2._Label1.pack_forget()
  133.     # LabelEff.pack_forget()
  134.     # if (StopWatch1._running and StopWatch2._running) :
  135.    
  136.         # StopWatch1.Stop()
  137.         # StopWatch2.Start()
  138.         # root.configure(bg='orange')
  139.         # StopWatch1._Label1.configure(bg='orange')
  140.         # StopWatch1.configure(bg='orange')
  141.         # StopWatch2._Label1.configure(bg='orange')
  142.         # StopWatch2.configure(bg='orange')
  143.     if  (StopWatch1._running==1 and StopWatch2._running==0) :  
  144.         StopWatch1.Stop()
  145.         StopWatch1.Stop()
  146.         StopWatch2.Start()
  147.         StopWatch3.Stop()
  148.         StopWatch4.Start()
  149.         root.configure(bg='orange')
  150.         StopWatch1._Label1.configure(bg='orange')
  151.         StopWatch1.configure(bg='orange')
  152.         StopWatch2._Label1.configure(bg='orange')
  153.         StopWatch2.configure(bg='orange')
  154.         StopWatch3._Label1.configure(bg='orange')
  155.         StopWatch3.configure(bg='orange')
  156.         StopWatch4._Label1.configure(bg='orange')
  157.         StopWatch4.configure(bg='orange')
  158.     elif  (StopWatch1._running==0 and StopWatch2._running==0) :  
  159.    
  160.         StopWatch1.Stop()
  161.         StopWatch2.Start()
  162.         StopWatch3.Stop()
  163.         StopWatch4.Start()
  164.         root.configure(bg='orange')
  165.         StopWatch1._Label1.configure(bg='orange')
  166.         StopWatch1.configure(bg='orange')
  167.         StopWatch2._Label1.configure(bg='orange')
  168.         StopWatch2.configure(bg='orange')
  169.         StopWatch3._Label1.configure(bg='orange')
  170.         StopWatch3.configure(bg='orange')
  171.         StopWatch4._Label1.configure(bg='orange')
  172.         StopWatch4.configure(bg='orange')
  173.     elif  (StopWatch1._running==0 and StopWatch2._running==1) :  
  174.         StopWatch1.Start()
  175.         StopWatch2.Stop()
  176.         StopWatch3.Stop()
  177.         StopWatch4.Start()
  178.         root.configure(bg='lime')
  179.         StopWatch1._Label1.configure(bg='lime')
  180.         StopWatch1.configure(bg='lime')
  181.         StopWatch2._Label1.configure(bg='lime')
  182.         StopWatch2.configure(bg='lime')
  183.         StopWatch3._Label1.configure(bg='lime')
  184.         StopWatch3.configure(bg='lime')
  185.         StopWatch4._Label1.configure(bg='lime')
  186.         StopWatch4.configure(bg='lime')
  187. def mouse2Clicked():
  188.     global StopWatch1
  189.     global StopWatch2
  190.  
  191.    
  192.     # StopWatch1._Label1.pack()
  193.     # StopWatch2._Label1.pack()
  194.     # LabelEff.pack()
  195.     if (StopWatch3._running==1 ) :  
  196.         StopWatch1.Stop()
  197.         StopWatch2.Stop()
  198.         StopWatch3.Stop()
  199.         StopWatch4.Stop()
  200.         root.configure(bg='white')
  201.         StopWatch1._Label1.configure(bg='white')
  202.         StopWatch1.configure(bg='white')
  203.         StopWatch2._Label1.configure(bg='white')
  204.         StopWatch2.configure(bg='white')
  205.         StopWatch3._Label1.configure(bg='white')
  206.         StopWatch3.configure(bg='white')
  207.         StopWatch4._Label1.configure(bg='white')
  208.         StopWatch4.configure(bg='white')
  209.         # StopWatch1._Label1.pack_forget()        
  210.         # StopWatch2._Label1.pack_forget()
  211.         # LabelEff.pack_forget()
  212.     elif  (StopWatch3._running==0) :  
  213.         StopWatch1.Stop()
  214.         StopWatch2.Stop()
  215.         StopWatch3.Start()
  216.         StopWatch4.Start()
  217.        
  218.         root.configure(bg='red')
  219.         StopWatch1._Label1.configure(bg='red')
  220.         StopWatch1.configure(bg='red')
  221.         StopWatch2._Label1.configure(bg='red')
  222.         StopWatch2.configure(bg='red')
  223.         StopWatch3._Label1.configure(bg='red')
  224.         StopWatch3.configure(bg='red')
  225.         StopWatch4._Label1.configure(bg='red')
  226.         StopWatch4.configure(bg='red')
  227.        
  228.         # StopWatch1._Label1.pack_forget()        
  229.         # StopWatch2._Label1.pack_forget()
  230.         # LabelEff.pack_forget()
  231.     elif  (StopWatch1._running==0 and StopWatch2._running==0) :
  232.         # StopWatch1._Label1.pack()
  233.         # StopWatch2._Label1.pack()
  234.         pass
  235.     print("StopWatch1.timestr= ", StopWatch1._elapsedtime)    
  236.     print("StopWatch2.timestr= ", StopWatch2._elapsedtime)
  237.     print("Effeciency= ", round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  238.     Effeciency.set([int(100*round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2)), '%']) # convert date and time and
  239.  
  240. root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  241. # root.geometry("65x38+-2+0")
  242. root.geometry("65x78+-2+0")
  243.  
  244.  
  245. # root.geometry("47x38+-2+0")
  246. # root.geometry("100x100+-2+0")
  247. # root.minsize(150, 100)
  248. StopWatch1 = StopWatch(root)
  249. StopWatch1.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  250. # ----------------------
  251. # root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  252. StopWatch2 = StopWatch(root)
  253. StopWatch2.pack()# Tkinter Pack Geometry Manager
  254. # ----------------------
  255. # frame = tk.Frame(root, width=100, height=100)
  256. # ----------------------
  257. # ----------------------
  258. # ----------------------
  259. StopWatch3 = StopWatch(root)
  260. StopWatch3.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  261.  
  262.  
  263. StopWatch4 = StopWatch(root)
  264. StopWatch4.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  265.  
  266. def Reset():                                  
  267.     """ Reset the stopwatch. """
  268.     mouse2Clicked()
  269.     StopWatch1.Reset()
  270.     StopWatch2.Reset()  
  271. def Hide():
  272.     global StopWatch1
  273.     global StopWatch2
  274.    
  275.     StopWatch1._Label1.pack_forget()        
  276.     StopWatch2._Label1.pack_forget()
  277.     StopWatch3._Label1.pack_forget()        
  278.     StopWatch4._Label1.pack_forget()
  279. def Show():
  280.     global StopWatch1
  281.     global StopWatch2
  282.     StopWatch1._Label1.pack()
  283.     StopWatch2._Label1.pack()    
  284.     StopWatch3._Label1.pack()
  285.     StopWatch4._Label1.pack()  
  286.  
  287. def minimiser():
  288.     root.overrideredirect(0)
  289.     root.state('iconic')  
  290.             # root.iconify()    
  291.             # root.geometry("47x38+-2+0")
  292.             # root.overrideredirect(True)
  293. StopWatch1._Label1.pack_forget()
  294. StopWatch2._Label1.pack_forget()
  295. StopWatch3._Label1.pack_forget()
  296. StopWatch4._Label1.pack_forget()
  297.  
  298.  
  299. def new_window():
  300.     window = tk.Toplevel(root)
  301.     # WindowDraggable(window)
  302.     # window.overrideredirect(True) # turns off title bar, geometry
  303.     window.attributes( '-topmost', 1 ) # ADDITINAL topmost
  304.     # window.geometry("65x78+-2+0")
  305.    
  306.     StopWatch11 = StopWatch(window)
  307.     StopWatch11.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  308.     StopWatch22 = StopWatch(window)
  309.     StopWatch22.pack()# Tkinter Pack Geometry Manager
  310.     StopWatch33 = StopWatch(window)
  311.     StopWatch33.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  312.     StopWatch44 = StopWatch(window)
  313.     StopWatch44.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  314.    
  315.     window.bind("<Button-1>", lambda x=None: mouse1Clicked() )
  316.     window.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
  317.  
  318.     window.bind("<Alt-Button-2>", lambda x=None: new_window())
  319.     window.bind("<Shift-Button-2>", lambda x=None: Show())
  320.     window.bind("<Double-Button-2>", lambda x=None: Hide())
  321.  
  322.     # root.bind("<Alt-Button-2>", lambda x=None: Hide())
  323.     # root.bind("<Shift-Button-2>", lambda x=None: Show())
  324.  
  325.     window.bind("<Control-Button-2>", lambda x=None: sys.exit())
  326.     window.bind("<Control-Button-3>", lambda x=None: Reset())
  327.  
  328. root.bind("<Button-1>", lambda x=None: mouse1Clicked() )
  329. root.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
  330.  
  331. root.bind("<Alt-Button-2>", lambda x=None: new_window())
  332. root.bind("<Shift-Button-2>", lambda x=None: Show())
  333. root.bind("<Double-Button-2>", lambda x=None: Hide())
  334.  
  335. # root.bind("<Alt-Button-2>", lambda x=None: Hide())
  336. # root.bind("<Shift-Button-2>", lambda x=None: Show())
  337.  
  338. root.bind("<Control-Button-2>", lambda x=None: sys.exit())
  339. root.bind("<Control-Button-3>", lambda x=None: Reset())
  340.  
  341. ###################
  342.  
  343.  
  344. # ----------------------
  345. # ----------------------
  346. # ----------------------
  347.  
  348. # if StopWatch2._elapsedtime!=0 :      
  349.     # root.Label1 = tk.Label(root, textvariable=round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  350.     # root.Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  351.  
  352. Effeciency = tk.StringVar()  
  353. LabelEff = tk.Label(root, textvariable=Effeciency)
  354. # LabelEff.pack()
  355.  
  356.  
  357. # time.sleep(1)
  358. # Effeciency.set(StopWatch2._elapsedtime-StopWatch1._elapsedtime) # convert date and time and
  359.  
  360. # labelText = tk.StringVar()
  361. # depositLabel = tk.Label(root, textvariable=labelText)
  362.  
  363. # def updateDepositLabel(txt): # you may have to use *args in some cases
  364.     # global labelText
  365.     # labelText.set(txt)
  366.    
  367. # updateDepositLabel(5)
  368. # labelText.pack()
  369.  
  370. WindowDraggable(root)
  371. root.overrideredirect(True) # turns off title bar, geometry
  372. root.attributes( '-topmost', 1 ) # ADDITINAL topmost
  373.  
  374.  
  375. Show()
  376.  
  377. root.mainloop() #This method will loop forever, waiting for events from the user, until it exits the program
  378.  
Add Comment
Please, Sign In to add comment