Re bonjour,
Voilà un petit bout de code (à adapter à votre cas, j'ai travaillé sur une de mes bases) :
#!/usr/bin/python3 # -*- coding: utf-8 -*- ## Importation des bibliothèques from tkinter import * from tkinter import ttk from tkinter.messagebox import * from tkinter.simpledialog import * import sqlite3 import sys import copy ## Fin d'importation des bibliothèques class Des: def __init__(self, root): self.root = root self.root.title("Collection dés") self.root.geometry("670x300+15+10") self.root.configure (bg = "green") # variables self.id = StringVar () self.ville = StringVar () self.departement = StringVar () self.tableau = [] self.pos = 0 id = Label(root, text= "Id", font = ("times new roman", 15, "bold"), bg= "cyan", fg= "black",width = 13) id.grid (row = 0, column = 0) id_txt = Entry(root, textvariable=self.id, font= ("times new roman", 15,"bold"), bg ="lightgrey", width = 50, relief = FLAT) id_txt.grid (row = 0, column = 1) ville = Label(root, text= "Ville", font = ("times new roman", 15, "bold"), bg= "cyan", fg= "black",width = 13) ville.grid (row = 1, column = 0) txt_ville = Entry(root, textvariable=self.ville, font= ("times new roman", 15,"bold"), bg ="lightgrey", width = 50, relief = FLAT) txt_ville.grid (row = 1, column = 1) depart = Label(root, text= "Département", font = ("times new roman", 15, "bold"), bg= "cyan", fg= "black",width = 13) depart.grid (row = 2, column = 0) txt_depart = Entry(root, textvariable=self.departement, font= ("times new roman", 15,"bold"), bg ="lightgrey", width = 50, relief = FLAT) txt_depart.grid (row = 2, column = 1) frameBouton =Frame (root, bg = 'green', border = 3, relief = RIDGE, width = 670, height = 100) frameBouton.grid(row = 3, column = 0, columnspan = 2, pady =30) frameBouton.grid_propagate (0) btArriere = Button (frameBouton, text = "<", font = ("times new roman", 25, "bold"),command = self.arriere) btArriere.grid (row = 0,column = 0,padx = 150, pady = 15) btAvant = Button (frameBouton, text = ">", font = ("times new roman", 25, "bold"),command = self.avant) btAvant.grid (row = 0, column = 1, padx = 150) def recup (self) : self.tableau [:] = [] # On vide le tableau con = sqlite3.connect("departements.db") cur = con.cursor() cur.execute("SELECT * FROM des") rows = cur.fetchall() print ("ROWS", rows) if len (rows) > 0 : self.tableau = copy.deepcopy (rows) print ("TABLEAU", self.tableau) con.close() self.affichage () def affichage (self) : if len (self.tableau) > 0 : self.id.set (self.tableau [self.pos][0]) self.ville.set (self.tableau [self.pos][1]) self.departement.set (self.tableau [self.pos][2]) def arriere (self) : if self.pos > 0 : self.pos -= 1 self.affichage () def avant (self) : if self.pos < len(self.tableau) - 1 : self.pos += 1 self.affichage () root = Tk() obj = Des (root) obj.recup() # Récupération du premier jeu de données root.mainloop ()
Ce code ressemble beaucoup au votre.
Différences : j'ai placé 2 nouvelles variables (tableau et pos).
La fonction recup () récupère toutes les données de la table et les copie dans la variable tableau (via le module copy importé ligne 11).
La fonction affichage () modifie les variables StingVar pour affichage avec les valeurs du tableau en position pos.
J'ai mis 2 boutons permettant de modifier la variable pos.
La ligne obj.recup permet la récupération des premières données (avec pos = 0)
Bonjour,
Pensez à mettre le sujet en résolu.
Bonjour,
textvariable doit être une variable StringVar ().
Il faut donc créer une variable StringVar (), lui assigne une valeur (via set) et fournir cette variable à textvariable.
Exemple :
nomVariable = StringVar() nomVariable.set (self.nom) nom_txt = Entry(Gestion_Frame, textvariable = nomVariable, font = ("times new roman", 15), bg = "lightgrey") nom_txt.place(x=50,y=130,width=250)
bonjour,
c'est déjà fait :
# les variables self.id = StringVar() # id self.titre = StringVar() # Titre self.nom = StringVar() # Nom self.prenom = StringVar() # Prenom
cordialement
kyrob17
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionrebonjour,
En admettant que la valeur de la variable soit TARTEMPION :
self.nom = StringVar () self.nom.set ("TARTEMPION")
re bonjour Gandalfix,
voici le code complet :
#!/usr/bin/python -> page-de fichier formulaire.py python # -*- coding: utf-8 -*- -> formulaire d'inscription Formulaire sqlite3 # Python 3.11.1 -> jacky michaud import tkinter as tk import sys,io,os from tkinter import * from tkinter import messagebox from tkinter.messagebox import * import sqlite3 class Etudiant: def __init__(self, root): self.root = root self.root.title("Formulaire de jacky") self.root.geometry("1500x760+15+10") # les variables self.id = StringVar() # id self.titre = StringVar() # Titre self.nom = StringVar() # Nom self.prenom = StringVar() # Prenom self.mail = StringVar() # Mail self.telephone = StringVar() # Telephone self.date = StringVar() # Date self.cotisation = StringVar() # cotisation self.ville = StringVar() # ville self.code_postal = StringVar() # code_postal self.adresse = StringVar() # adresse # champs du formulaire Gestion_Frame = Frame(self.root, bd=10, relief=GROOVE, bg="cyan") Gestion_Frame.place(x=450, y=120, width=700, height=440) title = Label(Gestion_Frame, text="Lecture de la fiche", font=("ink Free", 25, "bold"), bg="cyan", fg="red") title.place(x=90, y=10) # Id id = Label(Gestion_Frame, text= "Id", font = ("times new roman", 15, "bold"), bg= "cyan", fg= "black") id.place(x=50, y=40) id_txt = Entry(Gestion_Frame, textvariable=self.id, font= ("times new roman", 15), bg ="lightgrey") id_txt.place(x=50,y=70,width=80) # id_txt.focus_set() # titre titre = Label(Gestion_Frame, text= "Titre", font=("times new roman", 15, "bold"), bg="cyan", fg= "black") titre.place(x=370, y=40) titre_txt = Entry(Gestion_Frame, textvariable=self.titre, font=("times new roman", 15), bg ="lightgrey") titre_txt.place(x=370,y=70,width=80) # nom nom = Label(Gestion_Frame, text= "Nom", font=("times new roman", 15, "bold"), bg="cyan", fg= "black") nom.place(x=50, y=100) nom_txt = Entry(Gestion_Frame, textvariable=self.nom, font= ("times new roman", 15), bg ="lightgrey") nom_txt.place(x=50,y=130,width=250) # prenom prenom = Label(Gestion_Frame, text= "Prénom", font=("times new roman", 15, "bold"), bg="cyan", fg= "black") prenom.place(x=370, y=100) prenom_txt = Entry(Gestion_Frame, textvariable= self.prenom, font=("times new roman", 15), bg ="lightgrey") prenom_txt.place(x=370,y=130,width=250) # mail mail = Label(Gestion_Frame, text= "E-mail", font=("times new roman", 15, "bold"), bg="cyan", fg= "black") mail.place(x=50, y=160) mail_txt = Entry(Gestion_Frame, textvariable= self.mail, font= ("times new roman", 15), bg ="lightgrey") mail_txt.place(x=50,y=190,width=250) # telephone telephone = Label(Gestion_Frame, text= "Téléphone", font= ("times new roman", 15, "bold"), bg="cyan", fg= "black") telephone.place(x=370, y=160) telephone_txt = Entry(Gestion_Frame, textvariable= self.telephone, font=("times new roman", 15), bg ="lightgrey") telephone_txt.place(x=370,y=190,width=250) # date date = Label(Gestion_Frame, text= "Date", font=("times new roman", 15, "bold"), bg="cyan", fg= "black") date.place(x=50, y=220) date_txt = Entry(Gestion_Frame, textvariable= self.date, font= ("times new roman", 15), bg ="lightgrey") date_txt.place(x=50,y=250,width=250) # cotisation cotisation = Label(Gestion_Frame, text= "Cotisation", font= ("times new roman", 15, "bold"), bg="cyan", fg= "black") cotisation.place(x=370, y=220) cotisation_txt = Entry(Gestion_Frame, textvariable= self.cotisation, font= ("times new roman", 15), bg ="lightgrey") cotisation_txt.place(x=370,y=250,width=250) # code_postal code_postal = Label(Gestion_Frame, text= "Code_postal", font= ("arial", 15, "bold"), bg="cyan", fg= "black") code_postal.place(x=50, y=280) code_postal_txt = Entry(Gestion_Frame, textvariable= self.code_postal, font= ("times new roman", 15), bg ="lightgrey") code_postal_txt.place(x=50,y=310,width=250) # adresse adresse = Label(Gestion_Frame, text="Adresse", font= ("times new roman", 15, "bold"), bg="cyan", fg= "black") adresse.place(x=370, y=280) adresse_txt = Entry(Gestion_Frame, textvariable= self.adresse, font= ("times new roman", 15), bg ="lightgrey") adresse_txt.place(x=370,y=310, width=300, height=90) # ville ville = Label(Gestion_Frame, text="Ville", font= ("times new roman", 15, "bold"), bg= "cyan", fg= "black") ville.place(x=50, y=340) ville_txt = Entry(Gestion_Frame, textvariable= self.ville, font= ("times new roman", 15), bg ="lightgrey") ville_txt.place(x=50,y=370,width=250) # connexion btn1 = Button(Gestion_Frame, text="Affichage", command=self.afficherRechertat, cursor="hand2", font=("times new roman", 15, "bold"), bg="cyan", fg="black") btn1.place(x=500, y=50, width=150) ############################ def afficherRechertat(self): con = sqlite3.connect("creerinscript.db") cur = con.cursor() cur.execute("SELECT * FROM formordi") rows = cur.fetchall() ### ### for row in rows: self.id = row[0] # id self.titre = row[1] # titre self.nom = row[2] # Nom self.prenom = row[3] # Prenom self.mail = row[4] # mail self.telephone = row[5] # telephone self.date = row[6] # Date self.cotisation = row[7] # cotisation self.ville = row[8] # ville self.code_postal = row[9] # code_postal self.adresse = row[10] # Adresse print(row[0]) self.information(self) messagebox.showinfo("Succes", "Enregistrement afficher") # self.reini() con.commit() con.close() # information affichage def information(self, ev): #cursors_row = self.tabl_resul.focus() #contents = self.tabl_resul.item(cursors_row) # row =[] self.id, # id self.titre, # Titre self.nom, # Nom self.prenom, # Prenom self.mail, # mail self.telephone, # Telephone self.date, # Date self.cotisation, # cotisation self.ville, # ville self.code_postal, # code_postal # self.adresse.delete("1.0", END) # Adresse self.adresse, # Adresse # reinitialisation """def reini(self): self.id="" # id self.titre="" # Titre self.nom="" # Nom self.prenom="" # Prenom self.mail="" # mail self.telephone="" # Telephone self.date="" # Date self.cotisation="" # cotisation self.ville="" # ville self.code_postal="" # code_postal self.adresse="" # Adresse""" def fenetre_login(self): self.root.destroy() import Login self.afficherRechertat() self.information() #self.reini() def quitte(self): os._exit(0) root=Tk() obj =Etudiant(root) root.mainloop() #####################################
peut-être vous y verrez plus clair ma logique,
la version d'origine avez ça :
# information def information(self, ev): cursors_row = self.tabl_resul.focus() contents = self.tabl_resul.item(cursors_row) row =contents["values"] self.id.set(row[0]), # id self.titre.set(row[1]), # Titre self.nom.set(row[2]), # Nom self.prenom.set(row[3]), # Prenom self.mail.set(row[4]), # mail self.telephone.set(row[5]), # Telephone self.date.set(row[6]), # Date self.cotisation.set(row[7]), # cotisation self.ville.set(row[8]), # ville self.code_postal.set(row[9]), # code_postal self.adresse.delete("1.0", END) # Adresse self.adresse.insert(END, row[10]), # Adresse
vs code n'en veut pas comme ça, alors je l'ai modifier.
encore merci.
cordialement
kyrob17
Bonjour,
Désolé de ne pas avoir répondu plus tôt, j'étais un tantinet occupé hier.
Question : Dans votre esprit, que doivent effectuer les fonctions afficherRechertat et information ?
bonjour Gandalfix,
c'est pour vérifier la lecture d"une base de donnée, si les modifications sont bien passées, mise en majuscule et minuscule, voir récupérer les cotisations.
je suis parti d'un script qui fonction bien pour remplir les fiches, en gros, j'ai changé la présentation pour la lecture.
merci cordialement
kyrob17
merci, je vais étudié
cordialement
kyrob17
bonjour Gandalfix,
Avec votre aide, j'ai réussi a résoudre mon problème, merci, et encore un grand merci.
cordialement
Kyrob17