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
|
# -*- coding: utf-8 -*-
import sqlite3
import Tkinter as tk
class ViewTable(tk.Toplevel):
def __init__(self):
tk.Toplevel.__init__(self)
conn = sqlite3.connect('bdd.sqlite')
cur = conn.cursor()
self.listEntree = cur.execute("SELECT rowid, * FROM mytable ORDER BY rowid").fetchall()
self.listeChamp = [desc[0] for desc in cur.description]
cur.close()
self.curEntree = 0
self.listStringVar = []
self.listEntry = []
self.createObject()
def createObject(self):
for i, champ in enumerate(self.listeChamp):
tk.Label(self, text=champ+": ").grid(row=i, column=0, sticky=tk.E)
varia = tk.StringVar()
self.listStringVar.append(varia)
entry = tk.Entry(self, textvariable=varia)
entry.grid(row=i, column=1)
self.listEntry.append(entry)
tk.Checkbutton(self, text="disable", command=lambda x=i: self.onDisable(x)).grid(row=i, column=3)
tk.Button(self, text="précédent", command=self.precedent).grid(row=i+1, column=0)
tk.Button(self, text="suivant", command=self.suivant).grid(row=i+1, column=1, sticky=tk.W)
self.showValues()
def suivant(self):
if self.curEntree+1 < len(self.listEntree):
self.curEntree += 1
self.showValues()
def precedent(self):
if self.curEntree > 0:
self.curEntree -= 1
self.showValues()
def onDisable(self, i):
if self.listEntry[i].cget("state") == "normal":
self.listEntry[i].config(state="disabled")
else:
self.listEntry[i].config(state="normal")
def showValues(self):
infoEntree = self.listEntree[self.curEntree]
for var, value in zip(self.listStringVar, infoEntree):
var.set(str(value))
root = tk.Tk()
tk.Button(root, text="voir la table", command=ViewTable).pack()
tk.Button(root, text="fermer", command=quit).pack()
root.mainloop() |
Partager