famansour

Tracker -- Hide effeciency +Show brut + function to hide/show counters

Sep 23rd, 2020
1,684
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.         root.configure(bg='red')
  138.         StopWatch1._Label1.configure(bg='red')
  139.         StopWatch1.configure(bg='red')
  140.         StopWatch2._Label1.configure(bg='red')
  141.         StopWatch2.configure(bg='red')    
  142.     elif  (StopWatch1._running==0 and StopWatch2._running==0) :  
  143.    
  144.         StopWatch1.Start()
  145.         StopWatch2.Start()
  146.         root.configure(bg='green')
  147.         StopWatch1._Label1.configure(bg='green')
  148.         StopWatch1.configure(bg='green')
  149.         StopWatch2._Label1.configure(bg='green')
  150.         StopWatch2.configure(bg='green')
  151.     elif  (StopWatch1._running==0 and StopWatch2._running==1) :  
  152.         StopWatch1.Start()
  153.         StopWatch2.Start()
  154.         root.configure(bg='green')
  155.         StopWatch1._Label1.configure(bg='green')
  156.         StopWatch1.configure(bg='green')
  157.         StopWatch2._Label1.configure(bg='green')
  158.         StopWatch2.configure(bg='green')
  159. def mouse2Clicked():
  160.     global StopWatch1
  161.     global StopWatch2
  162.  
  163.    
  164.     # StopWatch1._Label1.pack()
  165.     # StopWatch2._Label1.pack()
  166.     # LabelEff.pack()
  167.     if (StopWatch1._running==0 and StopWatch2._running==1) :  
  168.         StopWatch1.Stop()
  169.         StopWatch2.Stop()
  170.         root.configure(bg='white')
  171.         StopWatch1._Label1.configure(bg='white')
  172.         StopWatch1.configure(bg='white')
  173.         StopWatch2._Label1.configure(bg='white')
  174.         StopWatch2.configure(bg='white')
  175.        
  176.         StopWatch1._Label1.pack_forget()        
  177.         StopWatch2._Label1.pack_forget()
  178.         LabelEff.pack_forget()
  179.     elif  (StopWatch1._running==1 and StopWatch2._running==1) :  
  180.         StopWatch1.Stop()
  181.         StopWatch2.Stop()  
  182.         root.configure(bg='white')
  183.         StopWatch1._Label1.configure(bg='white')
  184.         StopWatch1.configure(bg='white')
  185.         StopWatch2._Label1.configure(bg='white')
  186.         StopWatch2.configure(bg='white')
  187.        
  188.         StopWatch1._Label1.pack_forget()        
  189.         StopWatch2._Label1.pack_forget()
  190.         LabelEff.pack_forget()
  191.     elif  (StopWatch1._running==0 and StopWatch2._running==0) :
  192.         # stopWatch1._Label1.pack()
  193.         # StopWatch2._Label1.pack()
  194.         # LabelEff.pack()
  195.         # app = Fullscreen_Example()
  196.         # StopWatch1._Label1.pack()
  197.         # StopWatch2._Label1.pack()
  198.         # root.attributes("-fullscreen", self.fullScreenState)
  199.         # StopWatch1._Label1.pack_forget()
  200.         # # StopWatch2._Label1.pack_forget()
  201.         StopWatch1._Label1.pack()
  202.         StopWatch2._Label1.pack()
  203.         # LabelEff.pack()
  204.         # StopWatch1._Label1.pack_forget()
  205.         # StopWatch2._Label1.pack_forget()
  206.         # LabelEff.pack_forget()
  207.     print("StopWatch1.timestr= ", StopWatch1._elapsedtime)    
  208.     print("StopWatch2.timestr= ", StopWatch2._elapsedtime)
  209.     print("Effeciency= ", round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  210.     Effeciency.set([int(100*round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2)), '%']) # convert date and time and
  211.  
  212. root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  213. root.geometry("65x38+-2+0")
  214. # root.geometry("47x38+-2+0")
  215. # root.geometry("100x100+-2+0")
  216. # root.minsize(150, 100)
  217. StopWatch1 = StopWatch(root)
  218. StopWatch1.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  219. # ----------------------
  220. # root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  221. StopWatch2 = StopWatch(root)
  222. StopWatch2.pack()# Tkinter Pack Geometry Manager
  223. # ----------------------
  224. # frame = tk.Frame(root, width=100, height=100)
  225. # ----------------------
  226. # ----------------------
  227. # ----------------------
  228.  
  229. def Reset():                                  
  230.     """ Reset the stopwatch. """
  231.     mouse2Clicked()
  232.     StopWatch1.Reset()
  233.     StopWatch2.Reset()  
  234. def Show():
  235.     global StopWatch1
  236.     global StopWatch2
  237.    
  238.     StopWatch1._Label1.pack_forget()        
  239.     StopWatch2._Label1.pack_forget()
  240. def Hide():
  241.     global StopWatch1
  242.     global StopWatch2
  243.    
  244.     StopWatch1._Label1.pack()
  245.     StopWatch2._Label1.pack()
  246.     # root.configure(bg='black')
  247.     # StopWatch1._Label1.configure(bg='black')
  248.     # StopWatch1.configure(bg='black')
  249.     # StopWatch2._Label1.configure(bg='black')
  250.     # StopWatch2.configure(bg='black')
  251.     # root.wm_attributes("-transparent", True)
  252.    
  253.     # root.attributes("-transparentcolor")
  254.     # root.config(bg='systemTransparent')
  255.    
  256.  
  257.     # root.lift()
  258.     # root.wm_attributes("-topmost", True)
  259.     # root.wm_attributes("-disabled", True)
  260.     # pass
  261. def minimiser():
  262.     root.overrideredirect(0)
  263.     root.state('iconic')  
  264.             # root.iconify()    
  265.             # root.geometry("47x38+-2+0")
  266.             # root.overrideredirect(True)
  267. StopWatch1._Label1.pack_forget()
  268. StopWatch2._Label1.pack_forget()
  269. root.bind("<Button-1>", lambda x=None: mouse1Clicked() )
  270. root.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
  271.  
  272. root.bind("<Control-Button-1>", lambda x=None: Hide())
  273. root.bind("<Shift-Button-1>", lambda x=None: Show())
  274.  
  275. root.bind("<Control-Button-2>", lambda x=None: sys.exit())
  276. root.bind("<Control-Button-3>", lambda x=None: Reset())
  277.  
  278.  
  279.  
  280.  
  281. # ----------------------
  282. # ----------------------
  283. # ----------------------
  284.  
  285. # if StopWatch2._elapsedtime!=0 :      
  286.     # root.Label1 = tk.Label(root, textvariable=round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  287.     # root.Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  288.  
  289. Effeciency = tk.StringVar()  
  290. LabelEff = tk.Label(root, textvariable=Effeciency)
  291. # LabelEff.pack()
  292.  
  293.  
  294. # time.sleep(1)
  295. # Effeciency.set(StopWatch2._elapsedtime-StopWatch1._elapsedtime) # convert date and time and
  296.  
  297. # labelText = tk.StringVar()
  298. # depositLabel = tk.Label(root, textvariable=labelText)
  299.  
  300. # def updateDepositLabel(txt): # you may have to use *args in some cases
  301.     # global labelText
  302.     # labelText.set(txt)
  303.    
  304. # updateDepositLabel(5)
  305. # labelText.pack()
  306.  
  307. WindowDraggable(root)
  308. root.overrideredirect(True) # turns off title bar, geometry
  309. root.attributes( '-topmost', 1 ) # ADDITINAL topmost
  310.  
  311.  
  312.  
  313.  
  314. root.mainloop() #This method will loop forever, waiting for events from the user, until it exits the program
  315.  
RAW Paste Data