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
| from tkinter import *
import tkinter as tk
from tkinter.constants import END
def init():
for item in range(0, 10):
ma_listbox.insert(END, "La valeur indice " + str(item))
def selection(event):
valeur = ma_listbox.curselection()
print(valeur[0])
ma_fenetre = Tk()
ma_fenetre.geometry("1000x750")
mon_canvas = Canvas(ma_fenetre)
ma_listbox = Listbox(mon_canvas)
mon_scrollbar = Scrollbar(mon_canvas, orient='vertical')
mon_canvas.grid(row=0, column=0)
ma_listbox.config(yscrollcommand=mon_scrollbar.set)
ma_listbox.grid(row=0, column=0, sticky=E)
mon_scrollbar.config(command=ma_listbox.yview)
mon_scrollbar.grid(row=0, column=1, sticky='ns')
txt1 = Label(ma_fenetre, text='Texte 1', bg="#41B77F")
txt1.grid(row=1, column=0, padx=2, pady=10, sticky=W)
value1 = StringVar()
entr1 = Entry(ma_fenetre, textvariable=value1, width=20)
entr1.grid(row=1, column=1, pady=10, sticky=W)
txt2 = Label(ma_fenetre, text='Texte 2', bg="#41B77F")
txt2.grid(row=2, column=0, padx=2, pady=10, sticky=W)
value2 = StringVar()
entr2 = Entry(ma_fenetre, textvariable=value2, width=20)
entr2.grid(row=2, column=1, pady=10, sticky=W)
ma_listbox.bind("<<ListboxSelect>>", selection)
init()
ma_fenetre.mainloop() |
Partager