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 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
# coding:utf-8
#version 3.x python
import sys
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox # Librairie des fenêtres d'alerte
import time
# ================= Liaison file py =========================
import HV_DB_BackEnd
class Main:
def __init__(self, root):
self.root = root
self.root.geometry("620x660+0+0")
if __name__ =='__main__':
root = Tk()
application = Main(root)
# --- Déclaration Variables - Tableaux
frames = [] # Liste Frames
global Liste_Full
Liste_Full = [] # Liste d'imbrication des L_List (sélection faites depuis Treeview)
# ======================== Frames Master ====================
MainFrame = LabelFrame(root, text="[TEST]", relief=FLAT)
MainFrame.place(x=5, y=5, width=650, height=600)
FrameCalc_1 = Frame(name='labels', relief=FLAT)
FrameCalc_1.place(x=5, y=415, width=650, height=300)
# ======================== Fonctions ========================
def test(HElist):
z = -1
for child in HElist.get_children():
z = z +1
time.sleep(1)
HElist.update()
HElist.selection_set(HElist.get_children()[z])
print("HElist.get_children()[z]", HElist.get_children()[z])
HElist.focus_force()
HElist.focus_set()
HElist.focus(HElist.get_children()[z])
HElist.update()
print(child)
# Création dynamiquement frame(s) contenant Labels selon la sélection faite depuis TreeView
def selectItem(a):
global frames
var = IntVar()
frame = Frame(FrameCalc_1) # frame généré dans la frame master
# === [Listing Table dans Widget Treeview] ===
curItem = HElist.focus()
Liste = HElist.item(curItem)["values"]
# =======================================
HElist.event_generate('<ButtonRelease-1>', when="now", command=test(HElist))
# =======================================
# === [Génére automatiquement de nouveaux widgets Labels] ===
frame.configure(relief=GROOVE)
frame.grid(row=len(frames) + 1, column=5, pady=1) # Nb de Colonne à générer - pady=intervale entre la prochaine
frame.columnconfigure(0, minsize=135) # Largeur de la Colonne
frame.columnconfigure(1, minsize=30)
frame.columnconfigure(2, minsize=30)
frame.columnconfigure(3, minsize=50)
frame.columnconfigure(4, minsize=30)
frame.columnconfigure(5, minsize=80)
frame.columnconfigure(6, minsize=0)
var.set(len(frames))
if len(frames) < 5:
L_Line = [] # Liste temporaire pour chaque sélection
Champ_Table = [1,3,5] # Liste des index de champ cible de la table cible à exploiter
# -- Génére 3 Labels "Nom", "IODE", "NaOH"
for i in range(len(Champ_Table)):
Label(frame, name='%s' % "lb_"+ str(i ), text=Liste[Champ_Table[i]]).grid(row=0, column=i)
ki = '%s' % "lb_"+ str(i) # Nom Label - type str
L_Line.append(Liste[Champ_Table[i]])
# -- Génère Label - Affiche le Nb de Frame généré
l = Label(frame, textvariable=var)
l.grid(row=0, column=6)
l.var = var
frames.append(frame) # liste des frames générée
Liste_Full.append(L_Line[0:len(L_Line)]) # Imbrique L_Line dans Liste_Full
# [TreeView widgets] - Affiche Table
def DisplayData():
# Insertion Table BD dans TreeView
a = 0
for i in HV_DB_BackEnd.loadRecord():
HElist.insert('', 'end', text=i[0], values=(i[0], i[1], i[2], i[3], i[4], i[5]))
a = a + 1
# ============================== Treeview & Scrollbar Vertical/Horizontal [XY] ========================
scrollbar_y = Scrollbar(MainFrame, orient='vertical') # Ascenseur Vertical
scrollbar_y.place(x=600, y=24, height=350)
HElist = Treeview(MainFrame, selectmode="browse", columns=(1,2,3,4,5,6), show="headings", yscrollcommand=scrollbar_y.set)
# En-tête
HElist.heading('#1', text="ID")
HElist.heading('#2', text="Nom")
HElist.heading('#3', text="C1")
HElist.heading('#4', text="C2")
HElist.heading('#5', text="C3")
HElist.heading('#6', text="C4")
HElist.place(x=2, y=2, width=600, height=400)
# Cache colonne(s)
exclusionlist = ['1'] # Colonne [ID] exclue d'affichage
displaycolumns = ['2', '3', '4', '5', '6'] # Colonne [xxx] affichées
for col in HElist["columns"]:
if not "%s" % col in exclusionlist:
pass
HElist["displaycolumns"] = displaycolumns
scrollbar_y.config(command=HElist.yview) # Ascenseur Vertical
HV_DB_BackEnd.loadRecord()
DisplayData()
HElist.bind('<ButtonRelease-1>', selectItem) # Le bouton de la souris a été relâché
root.mainloop() |
Partager