Advertisement
famansour

Tracker -- 2nd right click inactive (good)

Sep 23rd, 2020
1,698
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.80 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.         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.         pass
  195.     print("StopWatch1.timestr= ", StopWatch1._elapsedtime)    
  196.     print("StopWatch2.timestr= ", StopWatch2._elapsedtime)
  197.     print("Effeciency= ", round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  198.     Effeciency.set([int(100*round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2)), '%']) # convert date and time and
  199.  
  200. root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  201. root.geometry("65x38+-2+0")
  202. # root.geometry("47x38+-2+0")
  203. # root.geometry("100x100+-2+0")
  204. # root.minsize(150, 100)
  205. StopWatch1 = StopWatch(root)
  206. StopWatch1.pack()# Tkinter Pack Geometry Manager   side=tk.TOP
  207. # ----------------------
  208. # root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
  209. StopWatch2 = StopWatch(root)
  210. StopWatch2.pack()# Tkinter Pack Geometry Manager
  211. # ----------------------
  212. # frame = tk.Frame(root, width=100, height=100)
  213. # ----------------------
  214. # ----------------------
  215. # ----------------------
  216.  
  217. def Reset():                                  
  218.     """ Reset the stopwatch. """
  219.     mouse2Clicked()
  220.     StopWatch1.Reset()
  221.     StopWatch2.Reset()  
  222. def Show():
  223.     global StopWatch1
  224.     global StopWatch2
  225.    
  226.     StopWatch1._Label1.pack_forget()        
  227.     StopWatch2._Label1.pack_forget()
  228. def Hide():
  229.     global StopWatch1
  230.     global StopWatch2
  231.    
  232.     StopWatch1._Label1.pack()
  233.     StopWatch2._Label1.pack()
  234.     # root.configure(bg='black')
  235.     # StopWatch1._Label1.configure(bg='black')
  236.     # StopWatch1.configure(bg='black')
  237.     # StopWatch2._Label1.configure(bg='black')
  238.     # StopWatch2.configure(bg='black')
  239.     # root.wm_attributes("-transparent", True)
  240.    
  241.     # root.attributes("-transparentcolor")
  242.     # root.config(bg='systemTransparent')
  243.    
  244.  
  245.     # root.lift()
  246.     # root.wm_attributes("-topmost", True)
  247.     # root.wm_attributes("-disabled", True)
  248.     # pass
  249. def minimiser():
  250.     root.overrideredirect(0)
  251.     root.state('iconic')  
  252.             # root.iconify()    
  253.             # root.geometry("47x38+-2+0")
  254.             # root.overrideredirect(True)
  255. StopWatch1._Label1.pack_forget()
  256. StopWatch2._Label1.pack_forget()
  257. root.bind("<Button-1>", lambda x=None: mouse1Clicked() )
  258. root.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
  259.  
  260. root.bind("<Alt-Button-2>", lambda x=None: Hide())
  261. root.bind("<Shift-Button-2>", lambda x=None: Show())
  262.  
  263. # root.bind("<Alt-Button-2>", lambda x=None: Hide())
  264. # root.bind("<Shift-Button-2>", lambda x=None: Show())
  265.  
  266. root.bind("<Control-Button-2>", lambda x=None: sys.exit())
  267. root.bind("<Control-Button-3>", lambda x=None: Reset())
  268.  
  269.  
  270.  
  271.  
  272. # ----------------------
  273. # ----------------------
  274. # ----------------------
  275.  
  276. # if StopWatch2._elapsedtime!=0 :      
  277.     # root.Label1 = tk.Label(root, textvariable=round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
  278.     # root.Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
  279.  
  280. Effeciency = tk.StringVar()  
  281. LabelEff = tk.Label(root, textvariable=Effeciency)
  282. # LabelEff.pack()
  283.  
  284.  
  285. # time.sleep(1)
  286. # Effeciency.set(StopWatch2._elapsedtime-StopWatch1._elapsedtime) # convert date and time and
  287.  
  288. # labelText = tk.StringVar()
  289. # depositLabel = tk.Label(root, textvariable=labelText)
  290.  
  291. # def updateDepositLabel(txt): # you may have to use *args in some cases
  292.     # global labelText
  293.     # labelText.set(txt)
  294.    
  295. # updateDepositLabel(5)
  296. # labelText.pack()
  297.  
  298. WindowDraggable(root)
  299. root.overrideredirect(True) # turns off title bar, geometry
  300. root.attributes( '-topmost', 1 ) # ADDITINAL topmost
  301.  
  302.  
  303.  
  304.  
  305. root.mainloop() #This method will loop forever, waiting for events from the user, until it exits the program
  306.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement