From 6a0386135055d67fe11db772aa8f6c1d38beec9c Mon Sep 17 00:00:00 2001 From: "barraux.a" Date: Sun, 15 May 2022 16:16:49 +0200 Subject: [PATCH] Interface graphique --- lecture_csv.py | 9 ++++-- main.py | 76 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 57 insertions(+), 28 deletions(-) diff --git a/lecture_csv.py b/lecture_csv.py index dd1bf85..4b9ed43 100644 --- a/lecture_csv.py +++ b/lecture_csv.py @@ -2,9 +2,12 @@ import datetime def numeroJour(date): """renvoie un entier correspondant au numéro du jour correspondant (entre 1 et 365)""" - day = datetime.datetime.strptime(date, "%Y-%m-%d") - num_day = day.strftime('%j') - return num_day + try: + day = datetime.datetime.strptime(date, "%Y-%m-%d") + num_day = day.strftime('%j') + return int(num_day) + except(ValueError): + return None def lecture(name): """lit le fichier csv dont le nom est passé en paramètre, en renvoie trois tableau contenant diff --git a/main.py b/main.py index df880a0..dfb6c61 100644 --- a/main.py +++ b/main.py @@ -1,30 +1,56 @@ -from kivy.app import App -from kivy.graphics import Ellipse, Line -from kivy.uix.boxlayout import BoxLayout -from kivy.uix.textinput import TextInput +import tkinter as tk +from tkinter import messagebox +import lecture_csv -class CustomLayout(BoxLayout): - - def __init__(self, **kwargs): - super(CustomLayout, self).__init__(**kwargs) - with self.canvas.after: - pass - self.textinput = TextInput(text='Hello world', multiline=False) - self.add_widget(self.textinput) - self.textinput.bind(on_text_validate=self.on_enter) - - def on_enter(self,instance, value): - print('User pressed enter in', instance) +class Main_frame(tk.Frame): + """Créer la Frame principal""" + def __init__(self, root): + super().__init__(root) + self._build() + self.pack() - - -class MainApp(App): - - def build(self): - root = CustomLayout() - return root + def _build(self): + text_voisin = tk.Label(self, text='Entrez le nombre de voisins: ') + text_voisin.grid(column=2, row=0) + self.nombre_de_voisin = tk.Entry(self, width=20, textvariable=tk.IntVar()) + self.nombre_de_voisin.grid(column=3, row=0) + + text_date = tk.Label(self, text='Entrez la date : ') + self.date = tk.Entry(self, width=20, textvariable=tk.StringVar()) + text_date.grid(column=0, row=1) + self.date.grid(column=1, row=1) + + text_temp_moy = tk.Label(self, text='Entrez la température moyenne : ') + self.temp_moy = tk.Entry(self, width=20, textvariable=tk.DoubleVar()) + text_temp_moy.grid(column=2, row=1) + self.temp_moy.grid(column=3, row=1) + + text_temp_ref = tk.Label(self, text='Entrez la température de référence : ') + self.temp_ref = tk.Entry(self, width=20, textvariable=tk.DoubleVar()) + text_temp_ref.grid(column=4, row=1) + self.temp_ref.grid(column=5, row=1) + + validate_button = tk.Button(self, text='Lancer la recherche', command=self.validate) + validate_button.grid(column=3, columnspan=2, row=2) + + def validate(self): + value = [self.nombre_de_voisin.get(), self.date.get(), self.temp_moy.get(), self.temp_ref.get()] + + try: + value[0] = int(value[0]) + value[2] = float(value[2]) + value[3] = float(value[3]) + except(ValueError): + messagebox.showerror('Erreur', 'Veuillez saisir des valeurs correctes !') + + if value[0] != 0 and lecture_csv.numeroJour(value[1]) != None: + value[1] = lecture_csv(value[1]) + print(value[1]) + else: + messagebox.showerror('Erreur', 'Date ou nombre de voisin nuls') if __name__ == '__main__': - MainApp().run() - + app = tk.Tk() + Main_frame(app) + app.mainloop() \ No newline at end of file