Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- # from mttkinter import mtTkinter as tk
- import time
- # import classes
- # import win32api
- # from threading import Thread
- import sys
- class Fullscreen_Example:
- def __init__(self):
- self.window = tk.Tk()
- self.window.attributes('-fullscreen', True)
- self.fullScreenState = False
- self.window.bind("<F11>", self.toggleFullScreen)
- self.window.bind('<ButtonRelease-2>', self.quitFullScreen)
- self.window.mainloop()
- # LabelEff = tk.Label(self, textvariable='AAAAAAAA')
- # LabelEff.pack()
- def toggleFullScreen(self, event):
- self.fullScreenState = not self.fullScreenState
- self.window.attributes("-fullscreen", self.fullScreenState)
- # LabelEff = tk.Label(self.window, textvariable='AAAAAAAA')
- LabelEff.pack()
- # LabelEff.pack()
- StopWatch1._Label1.pack()
- # StopWatch2._Label1.pack()
- # root = Tk()
- var = tk.StringVar()
- label = Label( self.window, textvariable=var, relief=RAISED )
- var.set("Hey!? How are you doing?")
- label.pack()
- self.window.mainloop()
- def quitFullScreen(self, event):
- # self.fullScreenState = False
- # self.window.attributes("-fullscreen", self.fullScreenState)
- self.window.bind('<ButtonRelease-2>', self.window.destroy())
- # var = tk.StringVar()
- # label = Label( self.window, textvariable=var, relief=RAISED )
- # var.set("Hey!? How are you doing?")
- # label.pack()
- # self.window.mainloop()
- class WindowDraggable():
- def __init__(self, root):
- self.root = root
- root.bind('<ButtonPress-2>', self.StartMove)
- root.bind('<ButtonRelease-2>', self.StopMove)
- root.bind('<B2-Motion>', self.OnMotion)
- def StartMove(self, event):
- self.x = event.x
- self.y = event.y
- def StopMove(self, event):
- self.x = None
- self.y = None
- def OnMotion(self,event):
- x = (event.x_root - self.x - self.root.winfo_rootx() + self.root.winfo_rootx())
- y = (event.y_root - self.y - self.root.winfo_rooty() + self.root.winfo_rooty())
- root.geometry("+%s+%s" % (x, y))
- class StopWatch(tk.Frame): #Class StopWatch inheriting from the Tkinter class Frame
- """ Implements a stop watch frame widget. """
- def __init__(self, parent=None, **kw):
- tk.Frame.__init__(self, parent, kw)
- # self.configure(bg='black')
- self._start = 0.0
- self._elapsedtime = 0.0
- self.timestr = tk.StringVar()
- self._running = 0
- self._Label1 = tk.Label(self, textvariable=self.timestr)
- self._setTime(self._elapsedtime)
- self._Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
- # def makeWidgets(self):
- # """ Make the time label. """
- # l = tk.Label(self, textvariable=self.timestr)
- # self._setTime(self._elapsedtime)
- # l.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
- # l.configure(bg='white')
- # return l
- def _update(self):
- """ Update the label with elapsed time. """
- self._elapsedtime = time.time() - self._start
- self._setTime(self._elapsedtime)
- self._timer = self.after(50, self._update)
- # print (self._timer, '= self.after')
- def _setTime(self, elap):
- """ Set the time string to Minutes:Seconds:Hundreths """
- hours = int(elap/(60.0*60.0))
- minutes = int((elap- hours*60.0*60.0)/60.0)
- seconds = int(elap- hours*60.0*60.0 - minutes*60.0)
- # hseconds = int((elap - minutes*60.0 - seconds)*100)
- self.timestr.set('%02d:%02d:%02d' % (hours, minutes, seconds)) # convert date and time and datetime objects to its equivalent string
- # print(('%02d:%02d:%02d' % (minutes, seconds, hseconds)))
- def Start(self):
- if not self._running:
- self._start = time.time() - self._elapsedtime
- self._update()
- self._running = 1
- def Stop(self):
- if self._running:
- self.after_cancel(self._timer)
- self._elapsedtime = time.time() - self._start
- self._setTime(self._elapsedtime)
- self._running = 0
- # print(self._elapsedtime)
- # print ('after_cancel(', self._timer, ')')
- def Reset(self):
- """ Reset the stopwatch. """
- self._start = time.time()
- self._elapsedtime = 0.0
- self._setTime(self._elapsedtime)
- # if not StopWatch1Local._running:
- def mouse1Clicked():
- global StopWatch1
- global StopWatch2
- StopWatch1._Label1.pack_forget()
- StopWatch2._Label1.pack_forget()
- LabelEff.pack_forget()
- if (StopWatch1._running and StopWatch2._running) :
- StopWatch1.Stop()
- root.configure(bg='red')
- StopWatch1._Label1.configure(bg='red')
- StopWatch1.configure(bg='red')
- StopWatch2._Label1.configure(bg='red')
- StopWatch2.configure(bg='red')
- elif (StopWatch1._running==0 and StopWatch2._running==0) :
- StopWatch1.Start()
- StopWatch2.Start()
- root.configure(bg='green')
- StopWatch1._Label1.configure(bg='green')
- StopWatch1.configure(bg='green')
- StopWatch2._Label1.configure(bg='green')
- StopWatch2.configure(bg='green')
- elif (StopWatch1._running==0 and StopWatch2._running==1) :
- StopWatch1.Start()
- StopWatch2.Start()
- root.configure(bg='green')
- StopWatch1._Label1.configure(bg='green')
- StopWatch1.configure(bg='green')
- StopWatch2._Label1.configure(bg='green')
- StopWatch2.configure(bg='green')
- def mouse2Clicked():
- global StopWatch1
- global StopWatch2
- StopWatch1._Label1.pack()
- # StopWatch2._Label1.pack()
- LabelEff.pack()
- if (StopWatch1._running==0 and StopWatch2._running==1) :
- StopWatch1.Stop()
- StopWatch2.Stop()
- root.configure(bg='white')
- StopWatch1._Label1.configure(bg='white')
- StopWatch1.configure(bg='white')
- StopWatch2._Label1.configure(bg='white')
- StopWatch2.configure(bg='white')
- elif (StopWatch1._running==1 and StopWatch2._running==1) :
- StopWatch1.Stop()
- StopWatch2.Stop()
- root.configure(bg='white')
- StopWatch1._Label1.configure(bg='white')
- StopWatch1.configure(bg='white')
- StopWatch2._Label1.configure(bg='white')
- StopWatch2.configure(bg='white')
- elif (StopWatch1._running==0 and StopWatch2._running==0) :
- # stopWatch1._Label1.pack()
- # StopWatch2._Label1.pack()
- # LabelEff.pack()
- # app = Fullscreen_Example()
- # StopWatch1._Label1.pack()
- # StopWatch2._Label1.pack()
- # root.attributes("-fullscreen", self.fullScreenState)
- # StopWatch1._Label1.pack_forget()
- # # StopWatch2._Label1.pack_forget()
- StopWatch1._Label1.pack_forget()
- # StopWatch2._Label1.pack_forget()
- LabelEff.pack_forget()
- print("StopWatch1.timestr= ", StopWatch1._elapsedtime)
- print("StopWatch2.timestr= ", StopWatch2._elapsedtime)
- print("Effeciency= ", round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
- Effeciency.set([int(100*round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2)), '%']) # convert date and time and
- root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
- root.geometry("65x38+-2+0")
- # root.geometry("47x38+-2+0")
- # root.geometry("100x100+-2+0")
- # root.minsize(150, 100)
- StopWatch1 = StopWatch(root)
- StopWatch1.pack()# Tkinter Pack Geometry Manager side=tk.TOP
- # ----------------------
- # root = tk.Tk() # initializing the tcl/tk interpreter and creating the root window
- StopWatch2 = StopWatch(root)
- # StopWatch2.pack()# Tkinter Pack Geometry Manager
- # ----------------------
- # frame = tk.Frame(root, width=100, height=100)
- # ----------------------
- # ----------------------
- # ----------------------
- def Reset():
- """ Reset the stopwatch. """
- mouse2Clicked()
- StopWatch1.Reset()
- StopWatch2.Reset()
- def Hide():
- # root.configure(bg='black')
- # StopWatch1._Label1.configure(bg='black')
- # StopWatch1.configure(bg='black')
- # StopWatch2._Label1.configure(bg='black')
- # StopWatch2.configure(bg='black')
- # root.wm_attributes("-transparent", True)
- # root.attributes("-transparentcolor")
- # root.config(bg='systemTransparent')
- # root.lift()
- # root.wm_attributes("-topmost", True)
- # root.wm_attributes("-disabled", True)
- pass
- def minimiser():
- root.overrideredirect(0)
- root.state('iconic')
- # root.iconify()
- # root.geometry("47x38+-2+0")
- # root.overrideredirect(True)
- StopWatch1._Label1.pack_forget()
- root.bind("<Button-1>", lambda x=None: mouse1Clicked() )
- root.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
- root.bind("<Control-Button-1>", lambda x=None: Hide())
- root.bind("<Control-Button-2>", lambda x=None: sys.exit())
- root.bind("<Control-Button-3>", lambda x=None: Reset())
- # ----------------------
- # ----------------------
- # ----------------------
- # if StopWatch2._elapsedtime!=0 :
- # root.Label1 = tk.Label(root, textvariable=round(StopWatch1._elapsedtime/StopWatch2._elapsedtime,2))
- # root.Label1.pack(fill=tk.X, expand=tk.NO, pady=2, padx=2)
- Effeciency = tk.StringVar()
- LabelEff = tk.Label(root, textvariable=Effeciency)
- LabelEff.pack()
- # time.sleep(1)
- # Effeciency.set(StopWatch2._elapsedtime-StopWatch1._elapsedtime) # convert date and time and
- # labelText = tk.StringVar()
- # depositLabel = tk.Label(root, textvariable=labelText)
- # def updateDepositLabel(txt): # you may have to use *args in some cases
- # global labelText
- # labelText.set(txt)
- # updateDepositLabel(5)
- # labelText.pack()
- WindowDraggable(root)
- root.overrideredirect(True) # turns off title bar, geometry
- root.attributes( '-topmost', 1 ) # ADDITINAL topmost
- root.mainloop() #This method will loop forever, waiting for events from the user, until it exits the program
Add Comment
Please, Sign In to add comment