Je travaille avec le gestionnaire de fenètres openbox and je voulais avoir une fenêtre qui pourrait m'indiquer l'heure (pour éviter les heuress supp…). J'ai donc développé un petit programme python pour ça.
root@host:~# pacman -S extra/tk
#! /usr/bin/python
# Role : Graphical Window to show current time
# Author : http://shebangthedolphins.net/
# 1.0 first version
#links that helped me :
# - https://tkdocs.com/tutorial/firstexample.html
# - https://stackoverflow.com/questions/44085554/how-to-use-the-after-method-to-make-a-callback-run-periodically
# - https://stackoverflow.com/questions/46279096/tkinter-update-variable-real-time
# - https://sebsauvage.net/python/gui/
#from tkinter import *
from tkinter import ttk
import datetime
import tkinter as tk
class WhatTime(tk.Tk):
def __init__(self,parent):
tk.Tk.__init__(self,parent)
self.parent = parent
self.initialize()
def initialize(self):
try:
self.grid()
self.resizable(False,False) #I don't want that the window can be resized
self.hour = tk.StringVar() #Set hour variable
self.wm_attributes("-topmost", 1) #Put window on top of others
self.PrintTime()
label = tk.Label(self,textvariable=self.hour,anchor="w",fg="green",bg="black") #set graphical theme
label.config(font=("Courier", 20, "bold")) #set font
label.grid(column=0,row=0,columnspan=1,sticky='EW')
except ValueError:
pass
def PrintTime(self):
try:
value = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') #set the time output
self.hour.set(value)
self.after(1000, self.PrintTime) #will be refreshed each second
except ValueError:
pass
if __name__ == "__main__":
app = WhatTime(None)
app.title('WT2I?')
app.mainloop()
Contact :