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 WindowWindowDraggable():
- def __init__(self, window):
- self.window = window
- window.bind('<ButtonPress-2>', self.StartMove)
- window.bind('<ButtonRelease-2>', self.StopMove)
- window.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.window.winfo_rootx() + self.window.winfo_rootx())
- y = (event.y_root - self.y - self.window.winfo_rooty() + self.window.winfo_rooty())
- window.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()
- # StopWatch2.Start()
- # root.configure(bg='orange')
- # StopWatch1._Label1.configure(bg='orange')
- # StopWatch1.configure(bg='orange')
- # StopWatch2._Label1.configure(bg='orange')
- # StopWatch2.configure(bg='orange')
- if (StopWatch1._running==1 and StopWatch2._running==0) :
- StopWatch1.Stop()
- StopWatch2.Start()
- StopWatch3.Stop()
- StopWatch4.Start()
- root.configure(bg='orange')
- StopWatch1._Label1.configure(bg='orange')
- StopWatch1.configure(bg='orange')
- StopWatch2._Label1.configure(bg='orange')
- StopWatch2.configure(bg='orange')
- StopWatch3._Label1.configure(bg='orange')
- StopWatch3.configure(bg='orange')
- StopWatch4._Label1.configure(bg='orange')
- StopWatch4.configure(bg='orange')
- ###
- StopWatch11.Stop()
- StopWatch22.Start()
- StopWatch33.Stop()
- StopWatch44.Start()
- window.configure(bg='orange')
- StopWatch11._Label1.configure(bg='orange')
- StopWatch11.configure(bg='orange')
- StopWatch22._Label1.configure(bg='orange')
- StopWatch22.configure(bg='orange')
- StopWatch33._Label1.configure(bg='orange')
- StopWatch33.configure(bg='orange')
- StopWatch44._Label1.configure(bg='orange')
- StopWatch44.configure(bg='orange')
- elif (StopWatch1._running==0 and StopWatch2._running==0) :
- StopWatch1.Stop()
- StopWatch2.Start()
- StopWatch3.Stop()
- StopWatch4.Start()
- root.configure(bg='orange')
- StopWatch1._Label1.configure(bg='orange')
- StopWatch1.configure(bg='orange')
- StopWatch2._Label1.configure(bg='orange')
- StopWatch2.configure(bg='orange')
- StopWatch3._Label1.configure(bg='orange')
- StopWatch3.configure(bg='orange')
- StopWatch4._Label1.configure(bg='orange')
- StopWatch4.configure(bg='orange')
- ######
- StopWatch11.Stop()
- StopWatch22.Start()
- StopWatch33.Stop()
- StopWatch44.Start()
- window.configure(bg='orange')
- StopWatch11._Label1.configure(bg='orange')
- StopWatch11.configure(bg='orange')
- StopWatch22._Label1.configure(bg='orange')
- StopWatch22.configure(bg='orange')
- StopWatch33._Label1.configure(bg='orange')
- StopWatch33.configure(bg='orange')
- StopWatch44._Label1.configure(bg='orange')
- StopWatch44.configure(bg='orange')
- elif (StopWatch1._running==0 and StopWatch2._running==1) :
- StopWatch1.Start()
- StopWatch2.Stop()
- StopWatch3.Stop()
- StopWatch4.Start()
- window.configure(bg='lime')
- StopWatch11._Label1.configure(bg='lime')
- StopWatch11.configure(bg='lime')
- StopWatch22._Label1.configure(bg='lime')
- StopWatch22.configure(bg='lime')
- StopWatch33._Label1.configure(bg='lime')
- StopWatch33.configure(bg='lime')
- StopWatch44._Label1.configure(bg='lime')
- StopWatch44.configure(bg='lime')
- ############
- StopWatch11.Start()
- StopWatch22.Stop()
- StopWatch33.Stop()
- StopWatch44.Start()
- root.configure(bg='lime')
- StopWatch1._Label1.configure(bg='lime')
- StopWatch1.configure(bg='lime')
- StopWatch2._Label1.configure(bg='lime')
- StopWatch2.configure(bg='lime')
- StopWatch3._Label1.configure(bg='lime')
- StopWatch3.configure(bg='lime')
- StopWatch4._Label1.configure(bg='lime')
- StopWatch4.configure(bg='lime')
- def mouse2Clicked():
- global StopWatch1
- global StopWatch2
- # StopWatch1._Label1.pack()
- # StopWatch2._Label1.pack()
- # LabelEff.pack()
- if (StopWatch3._running==1 ) :
- StopWatch1.Stop()
- StopWatch2.Stop()
- StopWatch3.Stop()
- StopWatch4.Stop()
- root.configure(bg='white')
- StopWatch1._Label1.configure(bg='white')
- StopWatch1.configure(bg='white')
- StopWatch2._Label1.configure(bg='white')
- StopWatch2.configure(bg='white')
- StopWatch3._Label1.configure(bg='white')
- StopWatch3.configure(bg='white')
- StopWatch4._Label1.configure(bg='white')
- StopWatch4.configure(bg='white')
- # StopWatch1._Label1.pack_forget()
- # StopWatch2._Label1.pack_forget()
- # LabelEff.pack_forget()
- ###
- StopWatch11.Stop()
- StopWatch22.Stop()
- StopWatch33.Stop()
- StopWatch44.Stop()
- window.configure(bg='white')
- StopWatch11._Label1.configure(bg='white')
- StopWatch11.configure(bg='white')
- StopWatch22._Label1.configure(bg='white')
- StopWatch22.configure(bg='white')
- StopWatch33._Label1.configure(bg='white')
- StopWatch33.configure(bg='white')
- StopWatch44._Label1.configure(bg='white')
- StopWatch44.configure(bg='white')
- elif (StopWatch3._running==0) :
- StopWatch1.Stop()
- StopWatch2.Stop()
- StopWatch3.Start()
- StopWatch4.Start()
- root.configure(bg='orangered')
- StopWatch1._Label1.configure(bg='orangered')
- StopWatch1.configure(bg='orangered')
- StopWatch2._Label1.configure(bg='orangered')
- StopWatch2.configure(bg='orangered')
- StopWatch3._Label1.configure(bg='orangered')
- StopWatch3.configure(bg='orangered')
- StopWatch4._Label1.configure(bg='orangered')
- StopWatch4.configure(bg='orangered')
- # StopWatch1._Label1.pack_forget()
- # StopWatch2._Label1.pack_forget()
- # LabelEff.pack_forget()
- ###
- StopWatch11.Stop()
- StopWatch22.Stop()
- StopWatch33.Start()
- StopWatch44.Start()
- window.configure(bg='orangered')
- StopWatch11._Label1.configure(bg='orangered')
- StopWatch11.configure(bg='orangered')
- StopWatch22._Label1.configure(bg='orangered')
- StopWatch22.configure(bg='orangered')
- StopWatch33._Label1.configure(bg='orangered')
- StopWatch33.configure(bg='orangered')
- StopWatch44._Label1.configure(bg='orangered')
- StopWatch44.configure(bg='orangered')
- 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("65x78+-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)
- # ----------------------
- # ----------------------
- # ----------------------
- StopWatch3 = StopWatch(root)
- StopWatch3.pack()# Tkinter Pack Geometry Manager side=tk.TOP
- StopWatch4 = StopWatch(root)
- StopWatch4.pack()# Tkinter Pack Geometry Manager side=tk.TOP
- def ResetSession():
- """ Reset the stopwatch. """
- StopWatch1.Reset()
- StopWatch2.Reset()
- StopWatch3.Reset()
- StopWatch4.Reset()
- def ResetDay():
- """ Reset the stopwatch. """
- StopWatch1.Reset()
- StopWatch2.Reset()
- StopWatch3.Reset()
- StopWatch4.Reset()
- StopWatch11.Reset()
- StopWatch22.Reset()
- StopWatch33.Reset()
- StopWatch44.Reset()
- HideShowSessionCount=0
- def HideShowSession():
- global HideShowSessionCount
- if HideShowSessionCount %2 ==0:
- StopWatch1._Label1.pack_forget()
- StopWatch2._Label1.pack_forget()
- StopWatch3._Label1.pack_forget()
- StopWatch4._Label1.pack_forget()
- HideShowSessionCount+=1
- else:
- StopWatch1._Label1.pack()
- StopWatch2._Label1.pack()
- StopWatch3._Label1.pack()
- StopWatch4._Label1.pack()
- HideShowSessionCount+=1
- HideShowDayCount=0
- def HideShowDay():
- global HideShowDayCount
- if HideShowDayCount %2 ==0:
- StopWatch11._Label1.pack_forget()
- StopWatch22._Label1.pack_forget()
- StopWatch33._Label1.pack_forget()
- StopWatch44._Label1.pack_forget()
- HideShowDayCount+=1
- else:
- StopWatch11._Label1.pack()
- StopWatch22._Label1.pack()
- StopWatch33._Label1.pack()
- StopWatch44._Label1.pack()
- HideShowDayCount+=1
- def ShowAll():
- StopWatch1._Label1.pack()
- StopWatch2._Label1.pack()
- StopWatch3._Label1.pack()
- StopWatch4._Label1.pack()
- StopWatch11._Label1.pack()
- StopWatch22._Label1.pack()
- StopWatch33._Label1.pack()
- StopWatch44._Label1.pack()
- def HideAll():
- StopWatch1._Label1.pack_forget()
- StopWatch2._Label1.pack_forget()
- StopWatch3._Label1.pack_forget()
- StopWatch4._Label1.pack_forget()
- StopWatch11._Label1.pack_forget()
- StopWatch22._Label1.pack_forget()
- StopWatch33._Label1.pack_forget()
- StopWatch44._Label1.pack_forget()
- def minimiser():
- root.overrideredirect(0)
- root.state('iconic')
- # root.iconify()
- # root.geometry("47x38+-2+0")
- # root.overrideredirect(True)
- StopWatch1._Label1.pack_forget()
- StopWatch2._Label1.pack_forget()
- StopWatch3._Label1.pack_forget()
- StopWatch4._Label1.pack_forget()
- def new_window():
- global window, StopWatch11, StopWatch22, StopWatch33, StopWatch44
- window = tk.Toplevel(root)
- WindowWindowDraggable(window)
- window.overrideredirect(True) # turns off title bar, geometry
- window.attributes( '-topmost', 1 ) # ADDITINAL topmost
- window.geometry("65x78+-2+0")
- StopWatch11 = StopWatch(window)
- StopWatch11.pack()# Tkinter Pack Geometry Manager side=tk.TOP
- StopWatch22 = StopWatch(window)
- StopWatch22.pack()# Tkinter Pack Geometry Manager
- StopWatch33 = StopWatch(window)
- StopWatch33.pack()# Tkinter Pack Geometry Manager side=tk.TOP
- StopWatch44 = StopWatch(window)
- StopWatch44.pack()# Tkinter Pack Geometry Manager side=tk.TOP
- window.bind("<Button-1>", lambda x=None: mouse1Clicked() )
- window.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
- window.bind("<Alt-Button-2>", lambda x=None: sys.exit())
- window.bind("<Control-Button-2>", lambda x=None: ResetDay())
- # window.bind("<Shift-Button-2>", lambda x=None: Show())
- window.bind("<Double-Button-2>", lambda x=None: HideShowDay())
- root.bind("<Button-1>", lambda x=None: mouse1Clicked() )
- root.bind("<Button-3>", lambda x=None: mouse2Clicked()) #bind Python functions and methods to events
- new_window()
- root.bind("<Alt-Button-2>", lambda x=None: sys.exit())
- root.bind("<Control-Button-2>", lambda x=None: ResetSession())
- # root.bind("<Shift-Button-2>", lambda x=None: Show())
- root.bind("<Double-Button-2>", lambda x=None: HideShowSession())
- # root.bind("<Alt-Button-2>", lambda x=None: Hide())
- # root.bind("<Shift-Button-2>", lambda x=None: Show())
- # 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
- HideAll()
- ShowAll()
- # Show()
- 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