famansour

Tracker -- commented win32api which cause error when building to .exe file

Sep 16th, 2020
1,066
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.  
  9. class StopWatch(tk.Frame):  #Class StopWatch inheriting from the Tkinter class Frame
  10.     """ Implements a stop watch frame widget. """                                                                
  11.     def __init__(self, parent=None, **kw):        
  12.         tk.Frame.__init__(self, parent, kw)
  13.         # self.configure(bg='black')
  14.         self._start = 0.0        
  15.         self._elapsedtime = 0.0
  16.         self.timestr = tk.StringVar()              
  17.         self._running = 0
  18.        
  19.         self._Label1 = tk.Label(self, textvariable=self.timestr)
  20.         self._setTime(self._elapsedtime)
  21.         self._Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  22.  
  23.  
  24.    
  25.     # def makeWidgets(self):                        
  26.         # """ Make the time label. """
  27.         # l = tk.Label(self, textvariable=self.timestr)
  28.         # self._setTime(self._elapsedtime)
  29.         # l.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  30.         # l.configure(bg='white')        
  31.         # return l  
  32.        
  33.     def _update(self):
  34.         """ Update the label with elapsed time. """
  35.         self._elapsedtime = time.time() - self._start
  36.         self._setTime(self._elapsedtime)
  37.         self._timer = self.after(50, self._update)
  38.         # print (self._timer, '= self.after')
  39.     def _setTime(self, elap):
  40.         """ Set the time string to Minutes:Seconds:Hundreths """
  41.         minutes = int(elap/60)
  42.         seconds = int(elap - minutes*60.0)
  43.         hseconds = int((elap - minutes*60.0 - seconds)*100)                
  44.         self.timestr.set('%02d:%02d:%02d' % (minutes, seconds, hseconds)) # convert date and time and datetime objects to its equivalent string
  45.         # print(('%02d:%02d:%02d' % (minutes, seconds, hseconds)))
  46.        
  47.     def Start(self):          
  48.         if not self._running:  
  49.             self._start = time.time() - self._elapsedtime
  50.             self._update()
  51.             self._running = 1
  52.     def Stop(self):
  53.         if self._running:
  54.             self.after_cancel(self._timer)            
  55.             self._elapsedtime = time.time() - self._start    
  56.             self._setTime(self._elapsedtime)
  57.             self._running = 0
  58.             # print(self._elapsedtime)
  59.             # print ('after_cancel(', self._timer, ')')
  60.  
  61.  
  62.     def Reset(self):                                  
  63.         """ Reset the stopwatch. """
  64.         self._start = time.time()        
  65.         self._elapsedtime = 0.0    
  66.         self._setTime(self._elapsedtime)
  67.    # if not StopWatch1Local._running:
  68. def mouse1Clicked():
  69.     global StopWatch1
  70.     global StopWatch2
  71.     if (StopWatch1._running and StopWatch2._running) :
  72.    
  73.         StopWatch1.Stop()
  74.         root.configure(bg='red')
  75.         StopWatch1._Label1.configure(bg='red')
  76.         StopWatch1.configure(bg='red')
  77.         StopWatch2._Label1.configure(bg='red')
  78.         StopWatch2.configure(bg='red')    
  79.     elif  (StopWatch1._running==0 and StopWatch2._running==0) :  
  80.    
  81.         StopWatch1.Start()
  82.         StopWatch2.Start()
  83.         root.configure(bg='green')
  84.         StopWatch1._Label1.configure(bg='green')
  85.         StopWatch1.configure(bg='green')
  86.         StopWatch2._Label1.configure(bg='green')
  87.         StopWatch2.configure(bg='green')
  88.     elif  (StopWatch1._running==0 and StopWatch2._running==1) :  
  89.         StopWatch1.Start()
  90.         StopWatch2.Start()
  91.         root.configure(bg='green')
  92.         StopWatch1._Label1.configure(bg='green')
  93.         StopWatch1.configure(bg='green')
  94.         StopWatch2._Label1.configure(bg='green')
  95.         StopWatch2.configure(bg='green')
  96. def mouse2Clicked():
  97.     global StopWatch1
  98.     global StopWatch2
  99.     if (StopWatch1._running==0 and StopWatch2._running==1) :  
  100.         StopWatch1.Stop()
  101.         StopWatch2.Stop()
  102.         root.configure(bg='white')
  103.         StopWatch1._Label1.configure(bg='white')
  104.         StopWatch1.configure(bg='white')
  105.         StopWatch2._Label1.configure(bg='white')
  106.         StopWatch2.configure(bg='white')
  107.     elif  (StopWatch1._running==1 and StopWatch2._running==1) :  
  108.         StopWatch1.Stop()
  109.         StopWatch2.Stop()  
  110.         root.configure(bg='white')
  111.         StopWatch1._Label1.configure(bg='white')
  112.         StopWatch1.configure(bg='white')
  113.         StopWatch2._Label1.configure(bg='white')
  114.         StopWatch2.configure(bg='white')
  115.     print("StopWatch1.timestr= ", StopWatch1._elapsedtime)    
  116.     print("StopWatch2.timestr= ", StopWatch2._elapsedtime)
  117.     print("Effeciency= ", round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  118.  
  119. root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  120. root.geometry("47x38+-2+0")
  121. # root.minsize(150, 100)
  122. StopWatch1 = StopWatch(root)
  123. StopWatch1.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  124. # ----------------------
  125. # root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  126. StopWatch2 = StopWatch(root)
  127. StopWatch2.pack()# Tkinter Pack Geometry Manager
  128. # ----------------------
  129. frame = tk.Frame(root, width=100, height=100)
  130. # ----------------------
  131. # ----------------------
  132. # ----------------------
  133.  
  134. def Reset():                                  
  135.     """ Reset the stopwatch. """
  136.     mouse2Clicked()
  137.     StopWatch1.Reset()
  138.     StopWatch2.Reset()  
  139. def Hide():        
  140.     # root.configure(bg='black')
  141.     # StopWatch1._Label1.configure(bg='black')
  142.     # StopWatch1.configure(bg='black')
  143.     # StopWatch2._Label1.configure(bg='black')
  144.     # StopWatch2.configure(bg='black')
  145.     # root.wm_attributes("-transparent", True)
  146.    
  147.     # root.attributes("-transparentcolor")
  148.     # root.config(bg='systemTransparent')
  149.    
  150.  
  151.     # root.lift()
  152.     # root.wm_attributes("-topmost", True)
  153.     # root.wm_attributes("-disabled", True)
  154.     pass
  155. def minimiser():
  156.     root.overrideredirect(0)
  157.     root.state('iconic')  
  158.             # root.iconify()    
  159.             # root.geometry("47x38+-2+0")
  160.             # root.overrideredirect(True)
  161. root.bind("<Button-1>", lambda x=None: mouse1Clicked() )
  162. root.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
  163. root.bind("<Control-Button-1>", lambda x=None: Hide())
  164. root.bind("<Control-Button-2>", lambda x=None: sys.exit())
  165. root.bind("<Control-Button-3>", lambda x=None: Reset())
  166.  
  167.  
  168.  
  169.  
  170. # ----------------------
  171. # ----------------------
  172. # ----------------------
  173. class WindowDraggable():
  174.  
  175.     def __init__(self, root):
  176.         self.root = root
  177.         root.bind('<ButtonPress-2>', self.StartMove)
  178.         root.bind('<ButtonRelease-2>', self.StopMove)
  179.         root.bind('<B2-Motion>', self.OnMotion)
  180.  
  181.     def StartMove(self, event):
  182.         self.x = event.x
  183.         self.y = event.y
  184.  
  185.     def StopMove(self, event):
  186.         self.x = None
  187.         self.y = None
  188.  
  189.     def OnMotion(self,event):
  190.         x = (event.x_root - self.x - self.root.winfo_rootx() + self.root.winfo_rootx())
  191.         y = (event.y_root - self.y - self.root.winfo_rooty() + self.root.winfo_rooty())
  192.         root.geometry("+%s+%s" % (x, y))
  193.        
  194. if StopWatch2._elapsedtime!=0 :      
  195.     root.Label1 = tk.Label(root, textvariable=round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  196.     root.Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  197.  
  198. WindowDraggable(root)
  199. root.overrideredirect(True) # turns off title bar, geometry
  200. root.attributes( '-topmost', 1 ) # ADDITINAL topmost
  201. root.mainloop() #This method will loop forever, waiting for events from the user, until it exits the program
  202.  
RAW Paste Data