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
|
class Interface(local_connexion): #interface principale
def __init__(self):
locale_connexion.__init__(self)
self.geometry('410x445'); self.title('Gestionnaire de connexions clients') # geom de l'obj interface
self['bg'] = 'light blue'
self.menu = Menu(self)
self.sousmenu2 = Menu(self.menu, activebackground='grey', tearoff=0)
self.menu.add_cascade(label='Connexion', state=ACTIVE, menu=self.sousmenu2) # menu connexion
############### sous menu 2 ##############
self.sousmenu2.add_command(label='Connexion locale',command=self.CL) #func* connexion local commandé par func* CL hérité de class local_connexion
class local_connexion(Tk):# interface de connexion
def __init__(self):
Tk.__init__(self)
def TEST_CL(self): # func* test de connexion
user = self.var_user.get(); self.password = var_password.get()
host = self.var_host.get(); self.port = var_port.get(); self.bdd = var_bdd.get()
db ='pq://%s:%s@%s:%s/%s' %(user, password, host, port, bdd)
try:
conn = postgresql.open(db); showinfo ('Infos connnexion', 'Connexion réussie')
except Exception:
print (db); print ('echec de connexion')
showerror("Infos connnexion", 'Echec de connexion! Veuillez vérifier les paramètres')
def CL(self): # fonction d'appel fenetre TK pour renseigner les infos de connexions
self.geometry('315x320'); self.title('Connexion locale au serveur'); self['bg'] = 'light blue'
self.label_frame = Label(self, text= "Saisissez les paramètres de connexion", fg='black', bg='light blue').place(x=1, y=15)
label_username = Label(self, text="Nom d'utilisateur :", fg='black', bg='light blue').place(x=10, y=55)
ligne_user = Entry(self, textvariable=self.var_user, width =26).place(x=130, y=55)
label_password = Label(self, text="Mot de passe :", fg='black', bg='light blue').place(x=10, y=100)
ligne_password = Entry(self, textvariable=self.var_password, width =26).place(x=130, y=100)
label_host = Label(self, text="Hôte :", fg='black', bg='light blue').place(x=10, y=145)
ligne_host = Entry(self, textvariable=self.var_host, width =26).place(x=130, y=145)
label_port = Label(self, text="Port :", fg='black', bg='light blue').place(x=10, y=190)
ligne_port = Entry(self, textvariable=self.var_port, width =26).place(x=130, y=190)
label_bdd = Label(self, text="Base de donnée :", fg='black', bg='light blue').place(x=10, y=235)
ligne_bdd = Entry(self, textvariable=self.var_bdd, width =26).place(x=130, y=235)
cl_ok = Button(self, text="Tester", width=6, command=self.TEST_CL).place(x=178, y=280) #self.ok_cl command
cl_annuler = Button(self, text="Annuler", width=6, command=quit).place(x=238, y=280)
self.mainloop()
#fin de class |
Partager