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
| # -*- coding: Utf-8 -*-
from tkinter import *
from tkinter.ttk import *
import mysql.connector
class consulter(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.initUI()
def initUI(self):
self.pack()
db = mysql.connector.connect(host="localhost",user="root",password="",database="stock")
cursor = db.cursor()
cursor.execute("SELECT * FROM produit")
results = cursor.fetchall()
sb = Scrollbar(self, orient=VERTICAL)
sb.pack(side=RIGHT, fill=Y)
lbox=Treeview(self,yscrollcommand=sb.set)
sb.configure(command=lbox.yview)
lbox['columns']=("a","b","c","d")
lbox.column("#0", anchor="w",width=50)
lbox.heading("#0", text='Num')
lbox.heading("a",text="Code")
lbox.column("a",minwidth=100,width=100)
lbox.heading("b", text="Nom")
lbox.column("b",minwidth=100,width=200)
lbox.heading("c", text="Quantité")
lbox.column("c",minwidth=0,width=100)
lbox.heading("d", text="Prix")
lbox.column("d",minwidth=100,width=100)
i=1
for r in results:
lbox.insert("","end",0,text=i,values=(r))
i+=1
lbox.pack()
db.close() |
Partager