1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
|
import tkinter as tk
from tkinter import *
from tkinter import ttk
from tkinter.ttk import *
from tkinter import font
#from configparser import ConfigParser
from PIL import Image, ImageTk
import datetime
#CFG_FILE = ConfigParser()
#CFG_FILE.optionxform = str
#CFG_FILE.read('ini/application.ini')
APPLICATION_NAME = 'MY_APPLICATION' #CFG_FILE.get('PARAMETERS', 'APPLICATION_NAME')
START_TIME = '05:30' #CFG_FILE.get('PARAMETERS', 'START_TIME')
PATH_OF_APPLICATION = 'C:\\temp\\MON_APPLICATION.exe' #CFG_FILE.get('PARAMETERS', 'PATH_OF_APPLICATION')
#Graphical Interface test---------------------------------------------------------------------------
class Application(ttk.Frame):
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
def __init__(self, main_window):
super().__init__(main_window)
main_window.title(APPLICATION_NAME)
#main_window.iconbitmap(r'ini/ico.ico')
#Size of my window interface----------------------------------------------------------------
w = 700
h = 150
ws = main_window.winfo_screenwidth()
hs = main_window.winfo_screenheight()
x = (ws/2) - (w/2)
y = (hs/2) - (h/2)
main_window.geometry('%dx%d+%d+%d' % (w, h, x, y))
#my_file = r"ini/bandeau.jpg"
#self.image = Image.open(my_file)
#self.x, self.y = self.image.size
#self.can=Canvas(main_window,width=self.x,height=self.y,bg='white', borderwidth=2, relief=RIDGE)
#self.can.bind("<Configure>",self.resize)
#self.can.pack(expand=NO,fill=BOTH)
self.GraphicalInterface()
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
def resize(self,event):
try:
self.can.delete(self.can.image)
except:
pass
self.img=self.image.resize((event.width,event.height))
self.mon_image = ImageTk.PhotoImage(self.img)
self.can.image=self.can.create_image(0, 0, image=self.mon_image, anchor=NW)
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
def GraphicalInterface(self):
#Define font--------------------------------------------------------------------------------
Myfont=font.Font(main_window, family='Courier new', size='10')
style = ttk.Style()
#Global container---------------------------------------------------------------------------
Menu_container = tk.Frame(main_window)
Menu_container.pack(expand=Y, fill=BOTH)
#Control menu frame-------------------------------------------------------------------------
ControlMenu_frame = tk.Frame(Menu_container, borderwidth=2, relief=RIDGE)
ControlMenu_frame.pack(side=LEFT, expand=Y, fill=BOTH)
Label(ControlMenu_frame, text="Time startup of application:", justify=LEFT, font=Myfont).pack(side=TOP, anchor=W)
global TIME_ENTRY
TIME_ENTRY = Entry(ControlMenu_frame, font=Myfont)
TIME_ENTRY.insert(END, START_TIME)
TIME_ENTRY.pack(side=TOP, fill=BOTH)
LABEL_2 = Label(ControlMenu_frame, text = 'Path of application to run:', justify=LEFT, font=Myfont).pack(side=TOP, anchor=W)
LABEL_3 = Label(ControlMenu_frame, text = PATH_OF_APPLICATION, justify=LEFT, font=Myfont).pack(side=TOP, anchor=W)
self.RunTheApplication()
#-----------------------------------------------------------------------------------------------
#-----------------------------------------------------------------------------------------------
def RunTheApplication(self):
# while True:
CheckVariable=''
DummyDate = datetime.datetime.now()
ActualTime = DummyDate.strftime('%H:%M')
ProgramTime = TIME_ENTRY.get()
print(DummyDate.strftime('%H:%M')+'_'+ProgramTime)
if ProgramTime == ActualTime and CheckVariable =='NO':
print('Run '+PATH_OF_APPLICATION)
CheckVariable='YES'
if ProgramTime == ActualTime and CheckVariable =='YES':
print('Je passe mon tour')
else:
CheckVariable='NO'
#Do not touch below---------------------------------------------------------------------------------
main_window = tk.Tk()
app = Application(main_window)
app.mainloop() |
Partager