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
| # import de la connexion ODBC pour Pycharm
import pyodbc
#import de lka fonction de creation d'interface graphique
from tkinter import *
#import de la fonction ouverture du navigateur internet
import webbrowser
# Définition des commande de lecture de la base
def read(conn):
print("Read")
cursor = conn.cursor()
donnees1 = [cursor.execute("SELECT TOP (10) [timestamp],[alarm_message], [alarm_class] FROM [AI_ATR].[dbo]."
"[ALARM_LOG]"
" order by timestamp desc"
)]
for row in cursor:
print(f'row = {row}')
print()
return
# Connexion a la Base AI_ATR
server = 'sqlaiatf\sql_ai_atf'
database = 'AI_ATR'
username = 'mes'
password = 'samsam'
conn = pyodbc.connect(
'DRIVER={SQL SERVER};SERVER=' + server + ';DATABASE=' + database + ';UID=' + username + ';PWD=' + password)
# Lecture dans la base AI_ATR
#read(conn)
# Fermeture de la connexion avec la base
#conn.close()
# creer la fenetre
class MyApp:
def __init__(self):
self.window = Tk()
self.window.title("Atelier Trancannage & Treillis Soudés")
self.window.geometry("720x480")
self.window.minsize(480, 360)
self.window.iconbitmap("Riva_Logo_Low_RGB.ico")
self.window.config(background='#157C79')
# initialization des composants
self.frame = Frame(self.window, bg='#157C79')
# creation des composants
self.create_widgets()
# empaquetage
self.frame.pack(expand=YES)
def create_widgets(self):
self.create_title()
self.create_subtitle()
self.create_button()
def create_title(self):
label_title = Label(self.frame, text="", font=("Courrier", 40), bg='#157C79',
fg='#C4B48C')
label_title.pack()
def create_subtitle(self):
label_subtitle = Label(self.frame, text="TRANCANNAGE", font=("Courrier", 25), bg='#157C79',
fg='#C4B48C')
label_subtitle.pack()
def create_button(self):
yt_button = Button(self.frame, text="Alarmes", font=("Courrier", 25), bg='#C4B48C', fg='#157C79',
command=self.dernieres_alarmes)
yt_button.pack(pady=25, fill=X)
def dernieres_alarmes(self):
read(conn)
# afficher
app = MyApp()
app.window.mainloop() |
Partager