famansour

Tracker V5 complete / Windows2 draggable works

Oct 20th, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.55 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. class WindowWindowDraggable():
  67.  
  68.     def __init__(self, window):
  69.         self.window = window
  70.         window.bind('<ButtonPress-2>', self.StartMove)
  71.         window.bind('<ButtonRelease-2>', self.StopMove)
  72.         window.bind('<B2-Motion>', self.OnMotion)
  73.  
  74.     def StartMove(self, event):
  75.         self.x = event.x
  76.         self.y = event.y
  77.  
  78.     def StopMove(self, event):
  79.         self.x = None
  80.         self.y = None
  81.  
  82.     def OnMotion(self,event):
  83.         x = (event.x_root - self.x - self.window.winfo_rootx() + self.window.winfo_rootx())
  84.         y = (event.y_root - self.y - self.window.winfo_rooty() + self.window.winfo_rooty())
  85.         window.geometry("+%s+%s" % (x, y))
  86.              
  87.        
  88. class StopWatch(tk.Frame):  #Class StopWatch inheriting from the Tkinter class Frame
  89.     """ Implements a stop watch frame widget. """                                                                
  90.     def __init__(self, parent=None, **kw):        
  91.         tk.Frame.__init__(self, parent, kw)
  92.         # self.configure(bg='black')
  93.         self._start = 0.0        
  94.         self._elapsedtime = 0.0
  95.         self.timestr = tk.StringVar()              
  96.         self._running = 0
  97.        
  98.         self._Label1 = tk.Label(self, textvariable=self.timestr)
  99.         self._setTime(self._elapsedtime)
  100.         self._Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  101.  
  102.        
  103.    
  104.     # def makeWidgets(self):                        
  105.         # """ Make the time label. """
  106.         # l = tk.Label(self, textvariable=self.timestr)
  107.         # self._setTime(self._elapsedtime)
  108.         # l.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  109.         # l.configure(bg='white')        
  110.         # return l  
  111.        
  112.     def _update(self):
  113.         """ Update the label with elapsed time. """
  114.         self._elapsedtime = time.time() - self._start
  115.         self._setTime(self._elapsedtime)
  116.         self._timer = self.after(50, self._update)
  117.         # print (self._timer, '= self.after')
  118.     def _setTime(self, elap):
  119.         """ Set the time string to Minutes:Seconds:Hundreths """
  120.         hours = int(elap/(60.0*60.0))
  121.         minutes = int((elap- hours*60.0*60.0)/60.0)
  122.         seconds = int(elap- hours*60.0*60.0 - minutes*60.0)
  123.         # hseconds = int((elap - minutes*60.0 - seconds)*100)                        
  124.         self.timestr.set('%02d:%02d:%02d' % (hours, minutes, seconds)) # convert date and time and datetime objects to its equivalent string
  125.         # print(('%02d:%02d:%02d' % (minutes, seconds, hseconds)))
  126.        
  127.     def Start(self):          
  128.         if not self._running:  
  129.             self._start = time.time() - self._elapsedtime
  130.             self._update()
  131.             self._running = 1
  132.     def Stop(self):
  133.         if self._running:
  134.             self.after_cancel(self._timer)            
  135.             self._elapsedtime = time.time() - self._start    
  136.             self._setTime(self._elapsedtime)
  137.             self._running = 0
  138.             # print(self._elapsedtime)
  139.             # print ('after_cancel(', self._timer, ')')
  140.  
  141.  
  142.     def Reset(self):                                  
  143.         """ Reset the stopwatch. """
  144.         self._start = time.time()        
  145.         self._elapsedtime = 0.0    
  146.         self._setTime(self._elapsedtime)
  147.    # if not StopWatch1Local._running:
  148. def mouse1Clicked():
  149.     global StopWatch1
  150.     global StopWatch2
  151.     # StopWatch1._Label1.pack_forget()
  152.     # StopWatch2._Label1.pack_forget()
  153.     # LabelEff.pack_forget()
  154.     # if (StopWatch1._running and StopWatch2._running) :
  155.    
  156.         # StopWatch1.Stop()
  157.         # StopWatch2.Start()
  158.         # root.configure(bg='orange')
  159.         # StopWatch1._Label1.configure(bg='orange')
  160.         # StopWatch1.configure(bg='orange')
  161.         # StopWatch2._Label1.configure(bg='orange')
  162.         # StopWatch2.configure(bg='orange')
  163.     if  (StopWatch1._running==1 and StopWatch2._running==0) :  
  164.  
  165.         StopWatch1.Stop()
  166.         StopWatch2.Start()
  167.         StopWatch3.Stop()
  168.         StopWatch4.Start()
  169.         root.configure(bg='orange')
  170.         StopWatch1._Label1.configure(bg='orange')
  171.         StopWatch1.configure(bg='orange')
  172.         StopWatch2._Label1.configure(bg='orange')
  173.         StopWatch2.configure(bg='orange')
  174.         StopWatch3._Label1.configure(bg='orange')
  175.         StopWatch3.configure(bg='orange')
  176.         StopWatch4._Label1.configure(bg='orange')
  177.         StopWatch4.configure(bg='orange')
  178.        
  179.         ###
  180.  
  181.         StopWatch11.Stop()
  182.         StopWatch22.Start()
  183.         StopWatch33.Stop()
  184.         StopWatch44.Start()
  185.         window.configure(bg='orange')
  186.         StopWatch11._Label1.configure(bg='orange')
  187.         StopWatch11.configure(bg='orange')
  188.         StopWatch22._Label1.configure(bg='orange')
  189.         StopWatch22.configure(bg='orange')
  190.         StopWatch33._Label1.configure(bg='orange')
  191.         StopWatch33.configure(bg='orange')
  192.         StopWatch44._Label1.configure(bg='orange')
  193.         StopWatch44.configure(bg='orange')
  194.     elif  (StopWatch1._running==0 and StopWatch2._running==0) :  
  195.    
  196.         StopWatch1.Stop()
  197.         StopWatch2.Start()
  198.         StopWatch3.Stop()
  199.         StopWatch4.Start()
  200.         root.configure(bg='orange')
  201.         StopWatch1._Label1.configure(bg='orange')
  202.         StopWatch1.configure(bg='orange')
  203.         StopWatch2._Label1.configure(bg='orange')
  204.         StopWatch2.configure(bg='orange')
  205.         StopWatch3._Label1.configure(bg='orange')
  206.         StopWatch3.configure(bg='orange')
  207.         StopWatch4._Label1.configure(bg='orange')
  208.         StopWatch4.configure(bg='orange')
  209.         ######
  210.        
  211.         StopWatch11.Stop()
  212.         StopWatch22.Start()
  213.         StopWatch33.Stop()
  214.         StopWatch44.Start()
  215.         window.configure(bg='orange')
  216.         StopWatch11._Label1.configure(bg='orange')
  217.         StopWatch11.configure(bg='orange')
  218.         StopWatch22._Label1.configure(bg='orange')
  219.         StopWatch22.configure(bg='orange')
  220.         StopWatch33._Label1.configure(bg='orange')
  221.         StopWatch33.configure(bg='orange')
  222.         StopWatch44._Label1.configure(bg='orange')
  223.         StopWatch44.configure(bg='orange')
  224.     elif  (StopWatch1._running==0 and StopWatch2._running==1) :  
  225.         StopWatch1.Start()
  226.         StopWatch2.Stop()
  227.         StopWatch3.Stop()
  228.         StopWatch4.Start()
  229.         window.configure(bg='lime')
  230.         StopWatch11._Label1.configure(bg='lime')
  231.         StopWatch11.configure(bg='lime')
  232.         StopWatch22._Label1.configure(bg='lime')
  233.         StopWatch22.configure(bg='lime')
  234.         StopWatch33._Label1.configure(bg='lime')
  235.         StopWatch33.configure(bg='lime')
  236.         StopWatch44._Label1.configure(bg='lime')
  237.         StopWatch44.configure(bg='lime')
  238.        
  239.         ############
  240.         StopWatch11.Start()
  241.         StopWatch22.Stop()
  242.         StopWatch33.Stop()
  243.         StopWatch44.Start()
  244.         root.configure(bg='lime')
  245.         StopWatch1._Label1.configure(bg='lime')
  246.         StopWatch1.configure(bg='lime')
  247.         StopWatch2._Label1.configure(bg='lime')
  248.         StopWatch2.configure(bg='lime')
  249.         StopWatch3._Label1.configure(bg='lime')
  250.         StopWatch3.configure(bg='lime')
  251.         StopWatch4._Label1.configure(bg='lime')
  252.         StopWatch4.configure(bg='lime')
  253. def mouse2Clicked():
  254.     global StopWatch1
  255.     global StopWatch2
  256.  
  257.    
  258.     # StopWatch1._Label1.pack()
  259.     # StopWatch2._Label1.pack()
  260.     # LabelEff.pack()
  261.     if (StopWatch3._running==1 ) :  
  262.         StopWatch1.Stop()
  263.         StopWatch2.Stop()
  264.         StopWatch3.Stop()
  265.         StopWatch4.Stop()
  266.         root.configure(bg='white')
  267.         StopWatch1._Label1.configure(bg='white')
  268.         StopWatch1.configure(bg='white')
  269.         StopWatch2._Label1.configure(bg='white')
  270.         StopWatch2.configure(bg='white')
  271.         StopWatch3._Label1.configure(bg='white')
  272.         StopWatch3.configure(bg='white')
  273.         StopWatch4._Label1.configure(bg='white')
  274.         StopWatch4.configure(bg='white')
  275.         # StopWatch1._Label1.pack_forget()        
  276.         # StopWatch2._Label1.pack_forget()
  277.         # LabelEff.pack_forget()
  278.        
  279.         ###
  280.        
  281.         StopWatch11.Stop()
  282.         StopWatch22.Stop()
  283.         StopWatch33.Stop()
  284.         StopWatch44.Stop()
  285.         window.configure(bg='white')
  286.         StopWatch11._Label1.configure(bg='white')
  287.         StopWatch11.configure(bg='white')
  288.         StopWatch22._Label1.configure(bg='white')
  289.         StopWatch22.configure(bg='white')
  290.         StopWatch33._Label1.configure(bg='white')
  291.         StopWatch33.configure(bg='white')
  292.         StopWatch44._Label1.configure(bg='white')
  293.         StopWatch44.configure(bg='white')
  294.     elif  (StopWatch3._running==0) :  
  295.         StopWatch1.Stop()
  296.         StopWatch2.Stop()
  297.         StopWatch3.Start()
  298.         StopWatch4.Start()
  299.        
  300.         root.configure(bg='orangered')
  301.         StopWatch1._Label1.configure(bg='orangered')
  302.         StopWatch1.configure(bg='orangered')
  303.         StopWatch2._Label1.configure(bg='orangered')
  304.         StopWatch2.configure(bg='orangered')
  305.         StopWatch3._Label1.configure(bg='orangered')
  306.         StopWatch3.configure(bg='orangered')
  307.         StopWatch4._Label1.configure(bg='orangered')
  308.         StopWatch4.configure(bg='orangered')
  309.        
  310.         # StopWatch1._Label1.pack_forget()        
  311.         # StopWatch2._Label1.pack_forget()
  312.         # LabelEff.pack_forget()
  313.        
  314.         ###
  315.        
  316.         StopWatch11.Stop()
  317.         StopWatch22.Stop()
  318.         StopWatch33.Start()
  319.         StopWatch44.Start()
  320.        
  321.         window.configure(bg='orangered')
  322.         StopWatch11._Label1.configure(bg='orangered')
  323.         StopWatch11.configure(bg='orangered')
  324.         StopWatch22._Label1.configure(bg='orangered')
  325.         StopWatch22.configure(bg='orangered')
  326.         StopWatch33._Label1.configure(bg='orangered')
  327.         StopWatch33.configure(bg='orangered')
  328.         StopWatch44._Label1.configure(bg='orangered')
  329.         StopWatch44.configure(bg='orangered')
  330.  
  331.  
  332.     print("StopWatch1.timestr= ", StopWatch1._elapsedtime)    
  333.     print("StopWatch2.timestr= ", StopWatch2._elapsedtime)
  334.     print("Effeciency= ", round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  335.     Effeciency.set([int(100*round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2)), '%']) # convert date and time and
  336.  
  337. root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  338. # root.geometry("65x38+-2+0")
  339. root.geometry("65x78+-2+0")
  340.  
  341.  
  342. # root.geometry("47x38+-2+0")
  343. # root.geometry("100x100+-2+0")
  344. # root.minsize(150, 100)
  345. StopWatch1 = StopWatch(root)
  346. StopWatch1.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  347. # ----------------------
  348. # root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  349. StopWatch2 = StopWatch(root)
  350. StopWatch2.pack()# Tkinter Pack Geometry Manager
  351. # ----------------------
  352. # frame = tk.Frame(root, width=100, height=100)
  353. # ----------------------
  354. # ----------------------
  355. # ----------------------
  356. StopWatch3 = StopWatch(root)
  357. StopWatch3.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  358.  
  359.  
  360. StopWatch4 = StopWatch(root)
  361. StopWatch4.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  362.  
  363. def ResetSession():                                  
  364.     """ Reset the stopwatch. """
  365.     StopWatch1.Reset()
  366.     StopWatch2.Reset()  
  367.     StopWatch3.Reset()
  368.     StopWatch4.Reset()  
  369.  
  370. def ResetDay():                                  
  371.     """ Reset the stopwatch. """
  372.     StopWatch1.Reset()
  373.     StopWatch2.Reset()  
  374.     StopWatch3.Reset()
  375.     StopWatch4.Reset()  
  376.     StopWatch11.Reset()
  377.     StopWatch22.Reset()  
  378.     StopWatch33.Reset()
  379.     StopWatch44.Reset()
  380. HideShowSessionCount=0
  381.  
  382. def HideShowSession():
  383.     global HideShowSessionCount
  384.     if HideShowSessionCount %2 ==0:
  385.         StopWatch1._Label1.pack_forget()        
  386.         StopWatch2._Label1.pack_forget()
  387.         StopWatch3._Label1.pack_forget()        
  388.         StopWatch4._Label1.pack_forget()
  389.         HideShowSessionCount+=1
  390.     else:
  391.         StopWatch1._Label1.pack()
  392.         StopWatch2._Label1.pack()    
  393.         StopWatch3._Label1.pack()
  394.         StopWatch4._Label1.pack()
  395.         HideShowSessionCount+=1
  396. HideShowDayCount=0    
  397. def HideShowDay():
  398.     global HideShowDayCount
  399.     if HideShowDayCount %2 ==0:
  400.         StopWatch11._Label1.pack_forget()        
  401.         StopWatch22._Label1.pack_forget()
  402.         StopWatch33._Label1.pack_forget()        
  403.         StopWatch44._Label1.pack_forget()
  404.         HideShowDayCount+=1
  405.     else:
  406.         StopWatch11._Label1.pack()
  407.         StopWatch22._Label1.pack()    
  408.         StopWatch33._Label1.pack()
  409.         StopWatch44._Label1.pack()
  410.         HideShowDayCount+=1
  411. def ShowAll():
  412.     StopWatch1._Label1.pack()
  413.     StopWatch2._Label1.pack()    
  414.     StopWatch3._Label1.pack()
  415.     StopWatch4._Label1.pack()
  416.     StopWatch11._Label1.pack()
  417.     StopWatch22._Label1.pack()    
  418.     StopWatch33._Label1.pack()
  419.     StopWatch44._Label1.pack()
  420. def HideAll():
  421.     StopWatch1._Label1.pack_forget()        
  422.     StopWatch2._Label1.pack_forget()
  423.     StopWatch3._Label1.pack_forget()        
  424.     StopWatch4._Label1.pack_forget()
  425.     StopWatch11._Label1.pack_forget()        
  426.     StopWatch22._Label1.pack_forget()
  427.     StopWatch33._Label1.pack_forget()        
  428.     StopWatch44._Label1.pack_forget()
  429.  
  430. def minimiser():
  431.     root.overrideredirect(0)
  432.     root.state('iconic')  
  433.             # root.iconify()    
  434.             # root.geometry("47x38+-2+0")
  435.             # root.overrideredirect(True)
  436. StopWatch1._Label1.pack_forget()
  437. StopWatch2._Label1.pack_forget()
  438. StopWatch3._Label1.pack_forget()
  439. StopWatch4._Label1.pack_forget()
  440.  
  441.  
  442. def new_window():
  443.     global window, StopWatch11, StopWatch22, StopWatch33, StopWatch44
  444.    
  445.     window = tk.Toplevel(root)
  446.     WindowWindowDraggable(window)
  447.     window.overrideredirect(True) # turns off title bar, geometry
  448.     window.attributes( '-topmost', 1 ) # ADDITINAL topmost
  449.     window.geometry("65x78+-2+0")
  450.    
  451.     StopWatch11 = StopWatch(window)
  452.     StopWatch11.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  453.     StopWatch22 = StopWatch(window)
  454.     StopWatch22.pack()# Tkinter Pack Geometry Manager
  455.     StopWatch33 = StopWatch(window)
  456.     StopWatch33.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  457.     StopWatch44 = StopWatch(window)
  458.     StopWatch44.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  459.    
  460.     window.bind("<Button-1>", lambda x=None: mouse1Clicked() )
  461.     window.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
  462.  
  463.     window.bind("<Alt-Button-2>", lambda x=None: sys.exit())
  464.     window.bind("<Control-Button-2>", lambda x=None: ResetDay())
  465.    
  466.    
  467.     # window.bind("<Shift-Button-2>", lambda x=None: Show())
  468.     window.bind("<Double-Button-2>", lambda x=None: HideShowDay())
  469.  
  470.    
  471.  
  472.  
  473. root.bind("<Button-1>", lambda x=None: mouse1Clicked() )
  474. root.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
  475. new_window()
  476.  
  477. root.bind("<Alt-Button-2>", lambda x=None: sys.exit())
  478. root.bind("<Control-Button-2>", lambda x=None: ResetSession())
  479.    
  480.  
  481. # root.bind("<Shift-Button-2>", lambda x=None: Show())
  482. root.bind("<Double-Button-2>", lambda x=None: HideShowSession())
  483.  
  484. # root.bind("<Alt-Button-2>", lambda x=None: Hide())
  485. # root.bind("<Shift-Button-2>", lambda x=None: Show())
  486.  
  487. # root.bind("<Control-Button-2>", lambda x=None: sys.exit())
  488. # root.bind("<Control-Button-3>", lambda x=None: Reset())
  489.  
  490. ###################
  491.  
  492.  
  493. # ----------------------
  494. # ----------------------
  495. # ----------------------
  496.  
  497. # if StopWatch2._elapsedtime!=0 :      
  498.     # root.Label1 = tk.Label(root, textvariable=round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  499.     # root.Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  500.  
  501. Effeciency = tk.StringVar()  
  502. LabelEff = tk.Label(root, textvariable=Effeciency)
  503. # LabelEff.pack()
  504.  
  505.  
  506. # time.sleep(1)
  507. # Effeciency.set(StopWatch2._elapsedtime-StopWatch1._elapsedtime) # convert date and time and
  508.  
  509. # labelText = tk.StringVar()
  510. # depositLabel = tk.Label(root, textvariable=labelText)
  511.  
  512. # def updateDepositLabel(txt): # you may have to use *args in some cases
  513.     # global labelText
  514.     # labelText.set(txt)
  515.    
  516. # updateDepositLabel(5)
  517. # labelText.pack()
  518.  
  519. WindowDraggable(root)
  520. root.overrideredirect(True) # turns off title bar, geometry
  521. root.attributes( '-topmost', 1 ) # ADDITINAL topmost
  522. HideAll()
  523. ShowAll()
  524. # Show()
  525.  
  526. root.mainloop() #This method will loop forever, waiting for events from the user, until it exits the program
  527.  
Add Comment
Please, Sign In to add comment