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
|
import tkinter as tk
from tkinter import ttk
from tkinter import *
def callbackFunc1(event):
print("Elément sélectionné dans combo1 : ", combo1.get())
if combo1.get() == "ST":
combo2["values"] = liste_B
elif combo1.get() == "Admin":
combo2["values"] = liste_C
elif combo1.get() == "Atsem":
combo2["values"] = liste_D
def callbackFunc2(event):
print("Elément sélectionné dans combo1 : ", combo2.get())
if combo2.get() == "Atelier":
combo3["values"]= listeB1
elif combo2.get() == "Batiment":
combo3["values"] = listeB2
elif combo2.get() == "Voirie":
combo3["values"] = listeB3
elif combo2.get() == "Espaces verts":
combo3["values"] = listeB4
fenetre = Tk()
fenetre.geometry('450x200')
fenetre.title("Test des combobox")
# Préparation des étiquettes
label1 = Label(fenetre, text="Choix 1")
label2 = Label(fenetre, text="Choix 2")
label3 = Label(fenetre, text="Choix 3")
label1.grid(column=0,row=0)
label2.grid(column=1,row=0)
label3.grid(column=2,row=0)
# Listes
liste_A = ["ST","Admin","Atsem","QUIT"]
liste_B = ["Atelier", "Batiment", "Voirie","Espaces verts"]
liste_C = ["Secrétaire","Comptable","DG","DGS","Accueil"]
liste_D = ["Accueil","Animation","Garderie","Cantine","Accompagnement"]
listeB1=["Marteau","Clé à molette","Tournevis","Ciseaux à bois"]
listeB2=["Bétonnière","Brouette","Perforateur"]
listeB3=["Camion","Lapidère","Marteau piqueur","Panneaux de signalisation"]
listeB4=["Tondeuse","Taille haies","Tronçonneuse","Débrousailleuse"]
liste_nul =[]
# Initialisation Combobox
combo1 = ttk.Combobox(fenetre, values= liste_A)
combo2 = ttk.Combobox(fenetre, values=liste_nul)
combo3 = ttk.Combobox(fenetre, values=liste_nul)
# affichage combobox
combo1.grid(column=0, row=1)
combo2.grid(column=1, row=1)
combo3.grid(column=2, row=1)
# Action
combo1.bind("<<ComboboxSelected>>", callbackFunc1)
combo2.bind("<<ComboboxSelected>>", callbackFunc2)
# affichage de la fenêtre
fenetre.mainloop() |