| 12
 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
 
 |  
# !-*- conding:utf-8 -*-
 
import sqlite3
from Tkinter import *
fen =Tk()
 
conn = sqlite3.connect("mydb")
cursor = conn.cursor()
 
try : # Je cree le fichier
    cursor.execute("""CREATE TABLE papeterie (lib VARCHAR(255) PRIMARY KEY, mont DECIMAL(10, 2))""")
except: # Sauf s'il existe deja ==> je l'ouvre directement (code provisoire)
    cursor.execute('select * from papeterie')
 
def enregistre(): #enregistre la saisie
    cursor.execute("INSERT INTO papeterie (lib, mont) VALUES (?, ?)",((m_lib),(m_mont)))
 
def affiche(): #affiche tout le fichier
    cursor.execute("SELECT * FROM papeterie")
    for line in cursor:
        print(line)
 
#affiche ecran et saisie
text1 = Label(fen, text='Veuillez entrer le libelle :')
text1.grid(row=1, column=1)
 
text2 = Label(fen, text='Veuillez entrer le montant :')
text2.grid(row=2, column=1)
 
m_lib = Entry(fen)
m_lib.grid( row=1, column=2)
 
m_mont = Entry(fen)
m_mont.grid( row=2, column=2)
 
bout1 = Button(fen,text="valider", command=enregistre)
bout1.grid( row=3, column=2)
 
bout2 = Button(fen,text="visualiser le fichier", command=affiche)
bout2.grid( row=5, column=2)
 
bout3 = Button(fen, text='quitter', command=fen.quit)
bout3.grid( row=7, column=2)
 
fen.mainloop()
 
conn.commit()
cursor.close() | 
Partager