Bonjour,

J'utilise un planificateur de tâche 'maison' dans un autre language. Je souhaite le convertir en python mais je suis confronté à plusieurs problèmes.

Commençons par le commencement:
-J'ai une fenêtre dans laquelle se trouve, un Entry dans lequel est stocké l'heure à laquelle le 'dit' script doit se lancer. Cet Entry est modifiable pour changé l'heure manuellement. Et j'ai un label dans lequel est afficher le chemin du script à lancer.

Ci-dessous mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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()
Mon problème est que ne sais pas quelle méthode utiliser (while, do, etc...), j'ai tenté le 'while true' dans ma fonction 'RunTheApplication' mais ma fenêtre d'interface ne s'affiche pas...

Merci par avance pour vos retours et vos aides.

Ci-joint le code de base:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
$pr=''
 
Do
	$Msg = GUIGetMsg()
 
	;Si l'heure est identique et que le programme n'a pas été déjà lancé
	If GUICtrlRead($DateStart)=GUICtrlRead($DateActual) And $Pr="Non" Then
		;~  MsgBox(0,"la ligne de commande pour exécuter le prog. est",GUICtrlRead($Programme))
		Run(GUICtrlRead($Programme))
		_FileWriteLog(@ScriptDir & "\log\AutoStartUp.log", GUICtrlRead($Programme) & ";" & StringUpper(@UserName) & ";" & @ComputerName & ";" & @IPAddress1)
    EndIf
    $Pr="Oui"
 
	;Comparaison de l'heure pour la bascule
	;Si l'heure est toujours identique et que le programme a été déjà lancé alors on empeche de le relancer siNon au autorise
	If GUICtrlRead($DateStart)=GUICtrlRead($DateActual) and $Pr="Oui" Then
	Else
		;SiNon si l'heure est redevenue différente on autorise à nouveau
		$Pr="Non"
	EndIf
 
	;Mise à jour de l'heure actuel
	If _NowTime (4)<> $DateActual Then
		GUICtrlSetData ($DateActual ,_NowTime(4))
	EndIf
 
 
Until $Msg = $GUI_EVENT_CLOSE Or $Msg = $Quitter