AttributeError: 'str' object has no attribute 'get' - Python Tkinter

Bonjour Isaac,
j’ai rentrer tout en minuscule les données, pour certaines je voudrai les convertir en majuscules. voici le scripte :

def ajou_etudiant(self):
        if self.id.get()=="" or self.nom.get()=="" or self.prenom.get()=="":
            messagebox.showerror("Erreur", "Vous n'avez pas rempli les champs obligatoires", parent=self.root)
        
        else:
            # nom en majuscule
            strg = self.nom.get()
            self.nom = strg.upper()
            strg = ""
            
            # prem. lettre en majuscule
            strg=self.prenom.get()
            self.prenom = strg.title()
            strg = ""
            
            # chaine en minuscule
            strg=self.mail.get()
            self.mail = strg.lower()
            strg = ""
            
            con = sqlite3.connect("creerinscript.db")
            cur = con.cursor()
            cur.execute("INSERT INTO formordi VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                ((self.id.get(),                 # Id
                self.titre.get(),                # Titre  
                self.nom.get(),                  # Nom 
                self.prenom.get(),               # Prenom
                self.mail.get(),                 # Mail
                self.telephone.get(),            # Telephone
                self.date.get(),                 # Date
                self.cotisation.get(),           # cotisation
                self.ville.get(),                # ville
                self.code_postal.get(),          # code postale
                self.adresse.get("1.0", END) ))) # Adresse
        
            con.commit()
            self.afficherRechertat()
            self.reini()
            con.close()
            messagebox.showinfo("Succes", "Enregistrement Effectue")

message d’erreur :

Exception in Tkinter callback
Traceback (most recent call last):
File « C:\Python\Python310\lib\tkinter_init_.py », line 1921, in call
return self.func(*args)
File « d:\Python\projet_python\Formulaire_adherent_2\Etudiant-B.py », line 233, in ajou_etudiant
self.nom.get(), # Nom
AttributeError: ‹ str › object has no attribute ‹ get ›

le script fonction tous en minuscule , impossible de le faire fonctionner avec la conversion ça bloque, je l’ai essaye avec un autre script ça fonctionne la conversion !!!
ci quelqu’un a une idée a me donnée ou une explication .
je suis preneur.
cordialement
kyrob

Bonjour @kyrob

En fait je trouve pas l’instruction self.str.get() dans le code ci-dessus c’est elle qui cause le problème. Parce que str n’est pas un objet de type Dictionary. Vérifier que str est de type Dictionary et qu’il n’est pas vide.

Bonjour Isaac,
les seuls ‹ str › que j’utilise sont la :

    # recherche info
    def rechercher_info(self):
       
        con = sqlite3.connect("creerinscript.db")
        cur = con.cursor()
        cur.execute("select * from formordi where " + str((self.recherch_par.get())) + " LIKE '%" + str((self.recherch.get())) + "%'")
        rows = cur.fetchall()
        
        if len(rows) !=0:
            self.tabl_resul.delete(* self.tabl_resul.get_children())
            
            for row in rows:
                self.tabl_resul.insert('', END, values=row)
                
            con.commit()
            con.close()

        # messagebox.showinfo("Succes", "Rechercher Effectue")
        
        rep = askokcancel("Succés","Voulez-vous l'imprimer")

que doit-je faire ?
merci
cordialement
kyrob

Le problème est que vous essayez d’appeler la méthode .get() à partir d’un objet String, mais les Strings ne possèdent pas cette méthode ou cet attribut. Vous pouvez vérifier ce qu’elles possèdent en exécutant dir(str) (dir est une méthode utile pour obtenir tous les attributs et méthodes d’un objet). Si vous supprimez le .get(), votre erreur disparaîtra.

bonjour Isaac,
j’ai fait des tentatives au point de plus rien comprendre.
je vous demande de l’aide.
je joint le script complet

#!/usr/bin/python               -> page-de fichier etudiant.py python
# -*- coding: utf-8 -*-         -> formulaire d'inscription adhérent sqlite3
# Python 3.10.2                 -> jacky michaud

import tkinter as tk
from tkinter import *
from tkinter import messagebox
from tkinter import ttk, messagebox
from tkinter.messagebox import *
import sqlite3
import sys,io,os

class Etudiant:
    def __init__(self, root):
        self.root = root
        self.root.title("Description")
        self.root.geometry("1510x775+5+5")
        
#########################

        # formulaire haut
        Gestion_Frame = Frame(self.root, bd=5, relief=GROOVE, bg="cyan")
        Gestion_Frame.place(x=7, y=10, width=1495, height=280)
        
        # 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.impression = StringVar()

        self.impression = ""
                
        # self.Adresse_txt = StringVar()
        self.recherch_par = StringVar()
        self.recherch = StringVar()

        gestion_title = Label(Gestion_Frame, text="Information de l'Adhérent", font=("times new roman", 30, "bold"), bg="cyan")
        gestion_title.place(x=5, y=0)

        # ID Ordinateur     # id
        id = Label(Gestion_Frame, text="ID adhérent : ", font=("times new roman", 15), bg="cyan")
        id.place(x=5, y=50, width=180)
        id_txt = Entry(Gestion_Frame, textvariable=self.id, font=("times new roman", 15), bg="lightgray")
        id_txt.place(x=150, y=50, width=300)
        id_txt.focus_set()
        
        # Titre  
        titre = Label(Gestion_Frame, text="Titre : ", font=("times new roman", 15), bg="cyan")
        titre.place(x=5, y=80, width=232)
        titre_txt = ttk.Combobox(Gestion_Frame, textvariable=self.titre, font=("times new roman", 15), state="readonly")
        titre_txt["values"]=(" Mr", " Mme", " Mlle")
        titre_txt.place(x=150, y=80,width=100)
                
        # Nom
        nom = Label(Gestion_Frame, text="Nom : ", font=("times new roman", 15), bg="cyan")
        nom.place(x=5, y=110, width=230)
        nom_txt = Entry(Gestion_Frame, textvariable=self.nom, font=("times new roman", 15), bg="lightgray")
        nom_txt.place(x=150, y=110, width=300)
        
        # prenom
        prenom = Label(Gestion_Frame, text="Prénom : ", font=("times new roman", 15), bg="cyan")
        prenom.place(x=5, y=140, width=210)
        prenom_txt = Entry(Gestion_Frame, textvariable=self.prenom, font=("times new roman", 15), bg="lightgray")
        prenom_txt.place(x=150, y=140, width=300)
        
        # mail
        mail = Label(Gestion_Frame, text="Mail : ", font=("times new roman", 15), bg="cyan")
        mail.place(x=5, y=170, width=230)
        mail_txt = Entry(Gestion_Frame, textvariable=self.mail, font=("times new roman", 15), bg="lightgray")
        mail_txt.place(x=150, y=170, width=300)

        
        # telephone
        telephone = Label(Gestion_Frame, text="Téléphone : ", font=("times new roman", 15), bg="cyan")
        telephone.place(x=5, y=200, width=188)
        telephone_txt = Entry(Gestion_Frame, textvariable=self.telephone, font=("times new roman", 15), bg="lightgray")
        telephone_txt.place(x=150, y=200, width=300)

        # date de naissance   
        date = Label(Gestion_Frame, text="Date : ", font=("times new roman", 15), bg="cyan")
        date.place(x=500, y=50, width=235)
        date_txt = Entry(Gestion_Frame, textvariable=self.date, font=("times new roman", 15), bg="lightgray")
        date_txt.place(x=650, y=50, width=300)
        
        # cotisation 
        cotisation = Label(Gestion_Frame, text="Cotisation : ", font=("times new roman", 15), bg="cyan")
        cotisation.place(x=500, y=80, width=190)
        cotisatione_txt = Entry(Gestion_Frame, textvariable=self.cotisation, font=("times new roman", 15), bg="lightgray")
        cotisatione_txt.place(x=650, y=80, width=300)
                
         # Ville    
        ville = Label(Gestion_Frame, text="Ville : ", font=("times new roman", 15), bg="cyan")
        ville.place(x=500, y=110, width=230)
        ville_txt = Entry(Gestion_Frame, textvariable=self.ville, font=("times new roman", 15), bg="lightgray")
        ville_txt.place(x=650, y=110, width=300)
        
        # code_postal   
        code_postal = Label(Gestion_Frame, text="code_postal : ", font=("times new roman", 15), bg="cyan")
        code_postal.place(x=500, y=140, width=172)
        code_postal_txt = Entry(Gestion_Frame, textvariable=self.code_postal, font=("times new roman", 15), bg="lightgray")
        code_postal_txt.place(x=650, y=140, width=300)

        # adresse
        adresse = Label(Gestion_Frame, text="Adresse : ", font=("times new roman", 15), bg="cyan")
        adresse.place(x=500, y=170, width=205)
        self.adresse = Text(Gestion_Frame, font=("times new roman", 15))
        self.adresse.place(x=650, y=170, width=300, height=90)

 
         # Bouton ajouter
        btn_ajouter = Button(Gestion_Frame, command=self.ajou_etudiant, text="Ajouter", font=("times new roman", 15), bd=10, relief=GROOVE, bg="green")
        btn_ajouter.place(x=1360,y=10, width=120)
        
        # Bouton modifier
        btn_modifier = Button(Gestion_Frame, command=self.modifier, text="Modifier", font=("times new roman", 15), bd=10, relief=GROOVE, bg="yellow")
        btn_modifier.place(x=1360,y=75, width=120)
        
        # Bouton Supprimer
        btn_supprimer = Button(Gestion_Frame, command=self.supprimer, text="Supprimer", font=("times new roman", 15), bd=10, relief=GROOVE, bg="red")
        btn_supprimer.place(x=1360,y=205, width=120)
        
        # Bouton Reinitialiser
        btn_reinitialiser = Button(Gestion_Frame, command=self.reini, text="Reinitialiser", font=("times new roman", 15), bd=10, relief=GROOVE, bg="gray")
        btn_reinitialiser.place(x=1360,y=140, width=120)

###########################

        # Recherche
        Details_Frame = Frame(self.root, bd=5, relief=GROOVE, bg="cyan")
        Details_Frame.place(x=7, y=300, width=1495, height=495)
        Affiche_resultat = Label(Details_Frame, text="Recherche par", font=("times new roman", 20, "bold"),bg="cyan")
        Affiche_resultat.place(x=10, y=30)

        rech = ttk.Combobox(Details_Frame, textvariable=self.recherch_par, font=("times new roman", 15), state="readonly")
        rech["values"]=(" Id", " Nom", " Ville")
        rech.place(x=190, y=35, width=160, height=35)

        #rech.current(0)
        rech_txt = Entry(Details_Frame, textvariable=self.recherch, font=("times new roman", 15), bd=5, relief=GROOVE)
        rech_txt.place(x=370,y=35, width=200, height=35)

        
        btn_rech =Button(Details_Frame, command=self.rechercher_info, text="Rechercher", font=("times new roman", 10), bd=5, bg="gray", relief=GROOVE)
        btn_rech.place(x=580, y=35, width=120, height=35)
        btn_afftou =Button(Details_Frame, command=self.afficherRechertat , text="Afficher tous", font=("times new roman", 10), bd=5, bg="gray", relief=GROOVE)
        btn_afftou.place(x=710, y=35, width=120, height=35)
        btn_quit =Button(Details_Frame, command=self.quitte , text="Quitter", font=("times new roman", 10,"bold"), bd=5, bg="red", relief=GROOVE)
        btn_quit.place(x=840, y=35, width=120, height=35)
        btn_quit =Button(Details_Frame, command=self.imprimer , text="Imprimer", font=("times new roman", 10,"bold"), bd=5, bg="green", relief=GROOVE)
        btn_quit.place(x=1100, y=35, width=120, height=35)
        
######################

        # Affichage bas
        result_Frame =Frame(Details_Frame, bd=5, relief=GROOVE, bg="cyan")
        result_Frame.place(x=10, y=100, width=1475, height=360)
        scroll_x = Scrollbar(result_Frame, orient=HORIZONTAL)
        scroll_y = Scrollbar(result_Frame, orient=VERTICAL)

        self.tabl_resul = ttk.Treeview(result_Frame, columns=("Id", "Titre", "Nom", "Prenom", "Mail", "Telephone", "Date", "Cotisation", "Ville", "Code_postal", "Adresse"), 
                                       xscrollcommand=scroll_x.set, 
                                       yscrollcommand=scroll_y.set)

        scroll_x.pack(side=BOTTOM, fill=X)
        scroll_y.pack(side=RIGHT, fill=Y)

        # nom  colonne affichage
        self.tabl_resul.heading("Id", text="Id")                     # id
        self.tabl_resul.heading("Titre", text="Titre")               # Titre
        self.tabl_resul.heading("Nom", text="Nom")                   # Nom 
        self.tabl_resul.heading("Prenom", text="Prénom")             # Prenom
        self.tabl_resul.heading("Mail", text="Mail")                 # Mail
        self.tabl_resul.heading("Telephone", text="Telephone")       # Telephone
        self.tabl_resul.heading("Date", text="Date")                 # Date
        self.tabl_resul.heading("Cotisation", text="Cotisation")     # cotisation
        self.tabl_resul.heading("Ville", text="Ville")               # ville
        self.tabl_resul.heading("Code_postal", text="Code_postal")   # code_postal
        self.tabl_resul.heading("Adresse", text="Adresse")           # Adresse

        self.tabl_resul["show"]="headings"

        # largeur colonne affichage
        self.tabl_resul.column("Id", width=20)            # id
        self.tabl_resul.column("Titre", width=40)         # Titre
        self.tabl_resul.column("Nom", width=150)          # Nom 
        self.tabl_resul.column("Prenom", width=150)       # Prenom
        self.tabl_resul.column("Mail", width=200)         # Mail
        self.tabl_resul.column("Telephone", width=100)    # Telephone
        self.tabl_resul.column("Date", width=100)         # Date
        self.tabl_resul.column("Cotisation", width=80)    # cotisation
        self.tabl_resul.column("Ville", width=150)        # ville
        self.tabl_resul.column("Code_postal", width=80)   # code_postal
        self.tabl_resul.column("Adresse", width=300)      # Adresse

        self.tabl_resul.pack()
        self.tabl_resul.bind("<ButtonRelease-1>", self.information)
        
        self.afficherRechertat()


    def ajou_etudiant(self):
        if self.id.get()=="" or self.nom.get()=="" or self.prenom.get()=="":
            messagebox.showerror("Erreur", "Vous n'avez pas rempli les champs obligatoires", parent=self.root)
        
        else:
            # nom en majuscule
            strg = self.nom.get()
            self.nom = strg.upper()
            strg = ""
            
            # prem. lettre en majuscule
            strg=self.prenom.get()
            self.prenom = strg.title()
            strg = ""
            
            # chaine en minuscule
            strg=self.mail.get()
            self.mail = strg.lower()
            strg = ""
            
            con = sqlite3.connect("creerinscript.db")
            cur = con.cursor()
            cur.execute("INSERT INTO formordi VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                ((self.id.get(),                 # Id
                self.titre.get(),                # Titre  
                self.nom.get(),                  # Nom 
                self.prenom.get(),               # Prenom
                self.mail.get(),                 # Mail
                self.telephone.get(),            # Telephone
                self.date.get(),                 # Date
                self.cotisation.get(),           # cotisation
                self.ville.get(),                # ville
                self.code_postal.get(),          # code postale
                self.adresse.get("1.0", END) ))) # Adresse
        
            con.commit()
            self.afficherRechertat()
            self.reini()
            con.close()
            messagebox.showinfo("Succes", "Enregistrement Effectue")


    def afficherRechertat(self):
        con = sqlite3.connect("creerinscript.db")
        cur = con.cursor()
        cur.execute("SELECT * FROM formordi")
        rows = cur.fetchall()
        if len(rows)!=0:
            self.tabl_resul.delete(* self.tabl_resul.get_children())
            for row in rows:
                self.tabl_resul.insert("", END, values=row)

        con.commit()
        con.close()

    # reinitialisation
    def reini(self):
        self.id.set("")                  # id
        self.titre.set("")               # Titre
        self.nom.set("")                 # Nom 
        self.prenom.set("")              # Prenom
        self.mail.set("")                # mail
        self.telephone.set("")           # Telephone
        self.date.set("")                # Date
        self.cotisation.set("")          # cotisation
        self.ville.set("")               # ville
        self.code_postal.set("")         # code_postal
        self.adresse.delete("1.0", END)  # Adresse

    # 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
       
       
       
        
       
    # Modifier
    def modifier(self):
        con = sqlite3.connect("creerinscript.db")
        cur = con.cursor()
        cur.execute("update formordi set titre=?, nom=?, prenom=?, mail=?, telephone=?, date=?, cotisation=?, ville=?, code_postal=?, adresse=? where id=?",
                    ((self.titre.get(),              # Titre
                    self.nom.get(),                  # Nom 
                    self.prenom.get(),               # Prenom 
                    self.mail.get(),                 # mail
                    self.telephone.get(),            # Telephone
                    self.date.get(),                 # Date  
                    self.cotisation.get(),           # cotisation    
                    self.ville.get(),                # ville 
                    self.code_postal.get(),          # code_postal
                    self.adresse.get("1.0", END),    # Adresse
                    self.id.get())))                 # id
        
        con.commit()
        messagebox.showinfo("Succes", "Modification Effectue")

        self.afficherRechertat()
        self.reini()
        con.close()

    # supprimer
    def supprimer(self):
        con = sqlite3.connect("creerinscript.db")
        cur = con.cursor()
        cur.execute("delete from formordi where id=?",(self.id.get()))
        con.commit()
        self.afficherRechertat()
        self.reini()
        con.close()

    
    

    # recherche info
    def rechercher_info(self):
       
        con = sqlite3.connect("creerinscript.db")
        cur = con.cursor()
        cur.execute("select * from formordi where " + str((self.recherch_par.get())) + " LIKE '%" + str((self.recherch.get())) + "%'")
        rows = cur.fetchall()
        
        if len(rows) !=0:
            self.tabl_resul.delete(* self.tabl_resul.get_children())
            
            for row in rows:
                self.tabl_resul.insert('', END, values=row)
                
            con.commit()
            con.close()

        # messagebox.showinfo("Succes", "Rechercher Effectue")
        
        rep = askokcancel("Succés","Voulez-vous l'imprimer")
        if rep == 1:
            oldstd=sys.stdout
            sys.stdout=io.StringIO()
            print("Id : ",(row[0])),                  # id
            print("Titre :",(row[1])),                # titre
            print("Nom : ",(row[2])),                 # Nom 
            print("Prénom : ",(row[3])),              # Prenom
            print("Mail : ",(row[4])),                # Coeurs
            print("Téléphone : ",(row[5])),           # Threads
            print("Date : ",(row[6])),                # Date
            print("Cotisation : ",(row[7])),          # cotisation
            print("Ville : ",(row[8])),               # ville
            print("Code_postal : ",(row[9])),         # code_postal
            print("Adresse : ",(row[10])),            # Adresse
            print("**************************************")
    # print("debut") 
            tmp_name="fichier_test.txt"
            with open(tmp_name,"w") as tmp :
                tmp.write(sys.stdout.getvalue())  # texte à imprimer dans fichier temporaire
        # imprimer le fichier temporaire via la commande 'notepad /P'
            with open(tmp_name,'r') as tmp :
                os.system('notepad /P '+tmp_name)
            os.remove(tmp_name)   # supprimer le fichier temporaire
        # restaurer le routage standard de stdout :
            sys.stdout=oldstd       # en principe, sys.__stdout__ ferait l'affaire
            messagebox.showinfo("Succes", "Impression Effectue")
        # fin de l'impression
        
            
    # imprimer
    def imprimer(self):
        oldstd=sys.stdout
        sys.stdout=io.StringIO()
        
        con = sqlite3.connect("creerinscript.db")
        cur = con.cursor()
        cur.execute("select * from formordi ")  
        rows = cur.fetchall()
        
        for row in rows:
                self.tabl_resul.insert('', END, values=row)
        # router tous les print dans une StringIO
                print("Id : ",(row[0])),                  # id
                print("Titre :",(row[1])),                # titre
                print("Nom : ",(row[2])),                 # Nom 
                print("Prénom : ",(row[3])),              # Prenom
                print("Mail : ",(row[4])),                # Coeurs
                print("Téléphone : ",(row[5])),           # Threads
                print("Date : ",(row[6])),                # Date
                print("Cotisation : ",(row[7])),          # cotisation
                print("Ville : ",(row[8])),               # ville
                print("Code_postal : ",(row[9])),         # code_postal
                print("Adresse : ",(row[10])),            # Adresse
                print("**************************************")
                # print("fichier fermer")    
        con.commit()
        con.close()
# print("Fin") 
        tmp_name="fichier_test.txt"
        with open(tmp_name,"w") as tmp :
            tmp.write(sys.stdout.getvalue())  # texte à imprimer dans fichier temporaire
        # imprimer le fichier temporaire via la commande 'notepad /P'
        with open(tmp_name,'r') as tmp :
            os.system('notepad /P '+tmp_name)
        os.remove(tmp_name)   # supprimer le fichier temporaire
        # restaurer le routage standard de stdout :
        sys.stdout=oldstd       # en principe, sys.__stdout__ ferait l'affaire
        messagebox.showinfo("Succes", "Impression Effectue")
        # fin de l'impression

        
                
    def quitte(self):
        exit()


root=Tk()
obj =Etudiant(root)
root.mainloop()


j’attend qu’il fonctionne bien, pour essayer de le couper en plusieur pages
merci d’avance pour l’aide.
cordialement
kyrob

Bonjour @kyrob
avez-vous essayer ce que je vous ai dit dans ma dernière réponse

Entre la ligne 231 - 241 essayer le code suivant:

cur.execute("INSERT INTO formordi VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
      ((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 postale
         self.adresse.get("1.0", END) ))) # Adresse

self.nom suffit pour afficher la valeur du nom.

Bonjour @Isaac.

la forme du scripte ne fonction pas très bien, j’ai réussi en faisant comme ça :

 con = sqlite3.connect("creerinscript.db")
            cur = con.cursor()
            cur.execute("INSERT INTO formordi VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                ((self.id.get(),                 # Id
                self.titre.get(),                # Titre  
                self.nom,                  # Nom 
                self.prenom,               # Prenom
                self.mail,                 # Mail
                self.telephone.get(),            # Telephone
                self.date.get(),                 # Date
                self.cotisation.get(),           # cotisation
                self.ville,                # ville
                self.code_postal.get(),          # code postale
                self.adresse.get("1.0", END) ))) # Adresse
        
            con.commit()
            self.afficherRechertat()
            self.reini()
            con.close()
            messagebox.showinfo("Succes", "Enregistrement Effectue")

mais j’ai des soucis avec reinitiation et supprime
reinitiation : ne remet pas les champ « Entry » a blanc la ou j’ai mis en majuscule
après différent tentative je recommencent a zéro.
merci quand même l’explication

je viens de recommencer avec l’original supprime ne fonctionne plus

message d’erreur :
File « d:\Python\projet_python\Formulaire_adherent_2\Etudiant-C.py », line 318, in supprimer
cur.execute(« delete from formordi where id=? », (self.id.get()))
sqlite3.ProgrammingError: Incorrect number of bindings supplied. The current statement uses 1, and there are 2 supplied.

# supprimer
    def supprimer(self):
        con = sqlite3.connect("creerinscript.db")
        cur = con.cursor()
        cur.execute("delete from formordi where id=?", (self.id.get()))
        con.commit()
        self.afficherRechertat()
        self.reini()
        con.close()

il s’arrête a sur cette ligne : cur.execute(« delete from formordi where id=? », (self.id.get()))
je m’excuse de vous ennuyez ainsi, je commence a y perdre nom latin.

cordialement
kyrob

Pas de soucis, c’est un plaisir de vous aider :wink:

Je vois que vous avez oublié la virgule, le deuxième paramètre de execute() doit être un tuple :

Donc essayer d’ajouter un virgule après self.id.get() comme suivant:

cur.execute("delete from formordi where id=?", (self.id.get(),))

Sans la virgule, (self.id.get()) est une expression composée, et non un tuple, et donc self.id.get() est traitée comme une séquence de caractères. Si cette chaîne comporte 2 caractères, Python considère qu’il s’agit de 2 valeurs. Par contre un tuple, Python le considère comme une seule valeur.

Vous pouvez aussi l’écrire sous forme de liste:

cur.execute("delete from formordi where id=?", [self.id.get()])

Bon courage :slightly_smiling_face:

Je vous remercie ça marche, je viens de faire plusieurs essais , simplement avec la virgule (1er exemple), je vais maintenant remettre la conversion en majuscule.
et encore un grand merci
cordialement
kyrob

Bonjour,

Comment effacer/supprimer le contenu d’un ‹ widget Entry › Tkinter ?

premier passage

1 ajouter d’inscription : fonctionne bien.
reini : passe sans s’arrêter et efface pas
2 reini deuxième passage : passe sans s’arrêter et efface pas.
3 modifier premier passage : passe sans s’arrêter et fonction bien.
reini : passe sans s’arrêter et efface pas
4 reini troisième passage sans s’arrêter : passe et efface pas.
5 supprimer premier passage : passe pas et fonctionne pas

# 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 

merci d’avance
cordialement
kyrob

Bonjour @kyrob

Pouvez-vous créer un nouveau sujet? car ce sujet est considérer comme résolu.

Merci :slightly_smiling_face:

Self.nom = StringVar()

#1
Nom_champ = Entry(Nom_fenêtre, options…, textvariable=self.nom)

Nom= self.nom.get()

#2

Nom = Nom_champ.get()