Creation d'un inventaire avec crud mysql

kendrik -  
yg_be Messages postés 23437 Date d'inscription   Statut Contributeur Dernière intervention   -
bonjour, je suis debutant en python je creer deux classes categorie et produit avec base de donnée mysql.
Je voudrais remplir une formulaire de table produit ou l'attribut id categorie est une clé etrangere dans la table produit . je ne sais pas par ou commencer .

2 réponses

  1. yg_be Messages postés 23437 Date d'inscription   Statut Contributeur Dernière intervention   Ambassadeur 1 588
     
    bonjour,
    maîtrises-tu MySQL?
    as-tu déjà fait d'autres exercices en Python?
    0
    1. kendrik
       
      je maitrise MySql
      et j'ai fais des exercices de bases en python
      0
      1. yg_be Messages postés 23437 Date d'inscription   Statut Contributeur Dernière intervention   1 588 > kendrik
         
        tu as créé les tables SQL? qu'est-ce qui te bloque?
        décris déjà ce que tu as réalisé.
        0
    2. kendrik
       
      je suis entrain de faire un test sur ca mais ca bloque
      ---------------------------------------------------------------------------------------------
      import pymysql
      from tkinter import*
      from tkinter import messagebox

      def search():
      try:
      con=pymsql.connect(user='root',host='localhost',password='',
      database="db")
      cur=con.cursor()
      sql="select*from student where rollno='%s'"%rollno.get()
      cur.execute(sql)
      result=cur.fetchone()
      name.set(result[1])
      age.set(result[2])
      e1.configure(state='disabled')
      con.close()
      except:
      messagebox.showinfo('No data...')
      clear()
      def clear():
      rollno.set('')
      name.set('')
      age.set('')
      e1.configure(state='normal')





      def add():
      try:
      con=pymsql.connect(user='root',host='localhost',password='',
      database="db")
      cur=con.cursor()
      sql="insert into student values ('%s','%s','%s'"\
      %(rollno.get(),name.get(),age.get())
      cur.execute(sql)
      con.commit()
      con.close()
      messagebox.showinfo('Succes')

      except:
      messagebox.showinfo('error')
      finally:
      clear()



      def update():
      try:
      con=pymsql.connect(user='root',host='localhost',password='',
      database="db")
      cur=con.cursor()
      sql="update student set name='%s',age=%s where rollno='%s'"\
      %(name.get(),age.get(),rollno.get())
      cur.execute(sql)
      con.commit()
      con.close()
      messagebox.showinfo('Update Succes')
      except:
      messagebox.showinfo('error')
      finally:
      clear()





      def delete():
      try:
      con=pymsql.connect(user='root',host='localhost',password='',
      database="db")
      cur=con.cursor()
      sql="delete from student where rollno='%s'"\
      %(rollno.get())
      cur.execute(sql)
      con.commit()
      con.close()
      messagebox.showinfo('Delete Succes')

      except:
      messagebox.showinfo('error')
      finally:
      clear()

      w1=Tk()
      w1.title('My App')
      w1.geometry('500x200')
      ptitle=Label(w1 , text='''PROGRAM''')
      ptitle.grid(row=0, column=0, columnspan=2)
      rollno=StringVar()
      name=StringVar()
      age=StringVar()
      l1=Label(w1, text='RollNo')
      e1=Entry(w1, textvariable=rollno)
      l2=Label(w1, text='Name')
      e2=Entry(w1, textvariable=name)
      l3=Label(w1, text='Age')
      e3=Entry(w1, textvariable=age)

      b1=Button(w1, text='search', command=search)
      b2=Button(w1, text=' add ', command=add)
      b3=Button(w1, text=' update ', command=update)
      b4=Button(w1, text=' delete ', command=delete)
      b5=Button(w1, text=' clear ', command=clear)


      l1.grid(row=1, column=0)
      e1.grid(row=1, column=1)
      b1.grid(row=1, column=2)

      l2.grid(row=2, column=0)
      e2.grid(row=2, column=1)

      l3.grid(row=3, column=0)
      e3.grid(row=3, column=1)

      b2.grid(row=4, column=0)
      b3.grid(row=4, column=1)
      b4.grid(row=5, column=0)
      b5.grid(row=5, column=1)

      w1.mainloop()
      0
      1. yg_be Messages postés 23437 Date d'inscription   Statut Contributeur Dernière intervention   1 588 > kendrik
         
        qu'est-ce qui te bloque?
        merci d'utiliser la coloration syntaxique quand tu partages du code.
        0
  2. kendrik
     
    import pymysql
    from tkinter import*
    from tkinter import messagebox

    def search():
    try:
    con=pymsql.connect(user='root',host='localhost',password='',
    database="db")
    cur=con.cursor()
    sql="select*from student where rollno='%s'"%rollno.get()
    cur.execute(sql)
    result=cur.fetchone()
    name.set(result[1])
    age.set(result[2])
    e1.configure(state='disabled')
    con.close()
    except:
    messagebox.showinfo('No data...')
    clear()
    def clear():
    rollno.set('')
    name.set('')
    age.set('')
    e1.configure(state='normal')

    def add():
    try:
    con=pymsql.connect(user='root',host='localhost',password='',
    database="db")
    cur=con.cursor()
    sql="insert into student values ('%s','%s','%s'"\
    %(rollno.get(),name.get(),age.get())
    cur.execute(sql)
    con.commit()
    con.close()
    messagebox.showinfo('Succes')

    except:
    messagebox.showinfo('error')
    finally:
    clear()

    def update():
    try:
    con=pymsql.connect(user='root',host='localhost',password='',
    database="db")
    cur=con.cursor()
    sql="update student set name='%s',age=%s where rollno='%s'"\
    %(name.get(),age.get(),rollno.get())
    cur.execute(sql)
    con.commit()
    con.close()
    messagebox.showinfo('Update Succes')

    except:
    messagebox.showinfo('error')
    finally:
    clear()
    
    
    
    
    
    def delete():
    try:
    con=pymsql.connect(user='root',host='localhost',password='',
    database="db")
    cur=con.cursor()
    sql="delete from student where rollno='%s'"\
    %(rollno.get())
    cur.execute(sql)
    con.commit()
    con.close()
    messagebox.showinfo('Delete Succes')
    
    except:
    messagebox.showinfo('error')
    finally:
    clear()
    
    w1=Tk()
    w1.title('My App')
    w1.geometry('500x200')
    ptitle=Label(w1 , text='''PROGRAM''')
    ptitle.grid(row=0, column=0, columnspan=2)
    rollno=StringVar()
    name=StringVar()
    age=StringVar()
    l1=Label(w1, text='RollNo')
    e1=Entry(w1, textvariable=rollno)
    l2=Label(w1, text='Name')
    e2=Entry(w1, textvariable=name)
    l3=Label(w1, text='Age')
    e3=Entry(w1, textvariable=age)
    
    b1=Button(w1, text='search', command=search)
    b2=Button(w1, text=' add ', command=add)
    b3=Button(w1, text=' update ', command=update)
    b4=Button(w1, text=' delete ', command=delete)
    b5=Button(w1, text=' clear ', command=clear)
    
    
    l1.grid(row=1, column=0)
    e1.grid(row=1, column=1)
    b1.grid(row=1, column=2)
    
    l2.grid(row=2, column=0)
    e2.grid(row=2, column=1)
    
    l3.grid(row=3, column=0)
    e3.grid(row=3, column=1)
    
    b2.grid(row=4, column=0)
    b3.grid(row=4, column=1)
    b4.grid(row=5, column=0)
    b5.grid(row=5, column=1)
    
    w1.mainloop()
    0
    1. yg_be Messages postés 23437 Date d'inscription   Statut Contributeur Dernière intervention   1 588
       
      tu n'as pas expliqué ce qui te bloque et, comme tu peux le voir, tu n'as pas correctement utilisé la coloration syntaxique.
      0