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
|
# G:/PROGRAMMATION\THONNY IDE\MES PROGRAMMES\PROGRAMMES\python-TKINTER\TKINTERCrazyListboxDansCanvas.py
from tkinter import *
fen = Tk()
fen.title("ESSAI AVEC CANVAS")
fen.geometry("600x600")
def selarticle_nom(event):
if Lb1.curselection():
selart = Articles[Lb1.curselection()[0]]
Lab1.configure(text=selart, bg='silver')
if Lb2.curselection():
selnom = Noms[Lb2.curselection()[0]]
Lab2.configure(text=selnom, bg='skyblue')
if Lb3.curselection():
selverbe = Verbes[Lb3.curselection()[0]]
Lab3.configure(text=selverbe, bg='palegreen')
police=("arial",12,"bold")
CanPlateau = Canvas(fen, width=500, height=50, bg='burlywood')
# pour placer le canvas aux coordonnées x,y remplacer monCanvas.pack() par place(x,y)
CanPlateau.place(x=10,y=150) # va placer le début du Canvas aux coordonnées (100,100).
Lab1=Label(CanPlateau,text="",font=police,width=12,height=3,relief=RAISED,bg='burlywood')
Lab1.grid(row=0,column=0)
Lab2=Label(CanPlateau,text="",font=police,width=12,height=3,relief=RAISED,bg='burlywood')
Lab2.grid(row=0,column=1)
Lab3=Label(CanPlateau,text="",font=police,width=12,height=3,relief=RAISED,bg='burlywood')
Lab3.grid(row=0,column=2)
CanListebox = Canvas(fen, width=500, height=50,bg='pink')
# pour placer le canvas aux coordonnées x,y remplacer monCanvas.pack() par place(x,y)
CanListebox.place(x=10,y=400) # va placer le début du Canvas aux coordonnées (x,y)
# Listbox Articles
Articles=["Le","La","Les","Un","Une","Des"]
nbmots=len(Articles)
print(nbmots)
Lb1=Listbox(CanListebox, height=nbmots,width=10, font=police,justify=LEFT,bg="silver")
for i in range(nbmots):
Lb1.insert(i,Articles[i])
Lb1.grid(row=0,column=0)
Lb1.bind('<<ListboxSelect>>',selarticle_nom)
# Listbox Noms Communs
Noms=["chien(s)","grenouille(s)","singe(s)","limace(s)","araignée(s)","cloporte(s)","anguille(s)","crevette(s)"]
nbmots=len(Noms)
print(nbmots)
Lb2=Listbox(CanListebox, height=nbmots,width=10, font=police,justify=LEFT,bg="skyblue")
for i in range(nbmots):
Lb2.insert(i,Noms[i])
Lb2.grid(row=0,column=1)
Lb2.bind('<<ListboxSelect>>',selarticle_nom)
# Listbox Verbes
Verbes=["mange(nt)","avale(nt)","saute(nt)","grimpe(nt)","attrape(nt)","marche(nt)","donne(nt)","va"]
nbmots=len(Noms)
print(nbmots)
Lb3=Listbox(CanListebox, height=nbmots,width=10, font=police,justify=LEFT,bg="palegreen")
for i in range(nbmots):
Lb3.insert(i,Verbes[i])
Lb3.grid(row=0,column=2)
Lb3.bind('<<ListboxSelect>>',selarticle_nom)
fen.mainloop() |
Partager