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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
| #-*- conding:utf-8 -*-
import sqlite3
from Tkinter import *
class Globals_Papeterie():
Index = 1 # Et pas 0
fen =Tk()
#---------------------------------------------------------------
conn = sqlite3.connect("mydb.sqlite")
cursor = conn.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS "papeterie"(id integer PRIMARY KEY AUTOINCREMENT,lib VARCHAR(255), "mont" DECIMAL(10, 2))""")
#---------------------------------------------------------------
def voir_une_ligne():
print cursor.execute("select * from papeterie").fetchone() # Te donne toujours l'enregistrement 1
def voir_ligne_choisie():
num = 1
for line in cursor.execute("select * from papeterie where id = (?)",(str(num))): # str(num) car num est de type int
print line
def liste():
for line in cursor.execute("SELECT * FROM papeterie"): print line
print 'Total : ', cursor.execute("SELECT COUNT(*) FROM papeterie").fetchall()[0][0]
# Sinon puisque tu galere avec les variables regarde ce que donne une classe Globals_Papeterie
def voir_suivant_valeur(Index):
print Index # A toi de gerer si Index < 0 ou fin de fichier (if). Regarde plus haut.
print cursor.execute("select * from papeterie where id = (?)",(Index)).fetchall()[0] # Ici Index est deja un string
Globals_Papeterie.Index = int(Index) # Donne a Globals_Papeterie.Index la valeur de Index (le Rech_Ind.get() donc)
def voir_ligne_par_ligne():
Globals_Papeterie.Index += 1 # Incremente de 1. A toi de gerer la fin ;).
print cursor.execute("select * from papeterie where id = (?)",(str(Globals_Papeterie.Index))).fetchall()[0] # Globals_Papeterie.Index en string bien sur
#---------------------------------------------------------------
Rech_Ind = Entry(fen)
Rech_Ind.grid( row=1, column=2)
bout0 = Button(fen,text="voir la ligne courante", command =voir_une_ligne)
bout0.grid(row=3, column = 2)
bout1 = Button(fen,text="entrez le num de ligne", command =voir_ligne_choisie)
bout1.grid(row=4, column = 2)
bout2 = Button(fen,text="lister le fichier", command=liste)
bout2.grid( row=5, column=2)
bout3 = Button(fen, text='quitter', command=fen.quit)
bout3.grid( row=6, column=2)
bout4 = Button(fen,text="voir suivant une entry", command = lambda: voir_suivant_valeur(Rech_Ind.get())) # http://python.developpez.com/faq/?page=Button
bout4.grid(row=7, column = 2)
bout5 = Button(fen,text="voir l'enregistrement suivant", command =voir_ligne_par_ligne)
bout5.grid(row=8, column = 2)
#---------------------------------------------------------------
fen.mainloop()
conn.commit()
conn.close() |
Partager