2 listebox et scrollbar

noradan Messages postés 20 Date d'inscription   Statut Membre Dernière intervention   -  
Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
je voudrais une liste déroulante, à sa droite une scrollbar et à coté un cadre (dans lequel va s'afficher les fichiers du répertoire sélectionné dans la liste)

Je n'arrive pas à mettre ça cote à cote.

Groupes =Frame(fen) # cadre pour l'ensemble des 2
Groupes.pack()
#Groupes.grid(row=0,coloumn=0)
GroupListe =Listbox(Groupes, height =15, width =25)
scrol =Scrollbar(Groupes, command =GroupListe.yview)
#scrol.grid(row=0,column=1)
GroupListe.config(yscrollcommand =scrol.set)
GroupListe.bind("<ButtonRelease-1>", Chargement)
GroupListe.pack(side =LEFT)
scrol.pack(expand =YES, fill =Y)
AlbumList=Listbox(fen,height=15,width=30)
AlbumList.pack(side=RIGHT)
#AlbumList.grid(row=0,column=1)

J'ai recopié un bout de code trouvé sur la toile, je comprends en gros ce que ça fait mais
Là , c'est en colonne. J'ai beau mettre des grid où je veux avec et sans pack (d'ailleur: que fait ce "pack" ? Il n'y a aucune indication dans le manuel tkinter) J'ai systématiquement
"cannot use geometry manager grid inside blablabla which already has slaves managed by pack"
et donc quand j'enlève tous les grid s'est empilé et je veux cote à cote

Merci

2 réponses

  1. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Bonjour Noradan,

    Un truc qui ressemblerait à ça ? :

    # -*- coding:Latin-1 -*-
    
    from tkinter import *
    
    def show_selection(evt):
    	''' Affiche la ligne selectionnée dans lb1 '''
    
    	i = lb1.curselection()[0]
    	lb2.insert(END,lb1.get(i))
    
    WIDTH=400
    HEIGHT=300
    
    main_win = Tk()
    main_win.configure(background = 'ivory')
    main_win.title('Test')
    main_win.geometry(str(WIDTH)+'x'+str(HEIGHT)+'+300+100')
    
    #Frame pour contenir list box + scroll bar
    f1 =Frame(main_win)
    f1.place(x=20,y=20)
    
    lb1 =Listbox(f1, height =10, width =30)
    lb1.pack(side =LEFT)
    for k in range(30):
    	lb1.insert(END, "Ligne numéro " + str(k))
    lb1.bind("<ButtonRelease-1>", show_selection)
    
    scrol =Scrollbar(f1, command = lb1.yview)
    scrol.pack(expand = YES, fill = Y)
    
    lb1.config(yscrollcommand = scrol.set)
    
    #List box pour afficher le résultat
    lb2 =Listbox(main_win, height =10, width =20)
    lb2.place(x=250, y=20)
    
    main_win.mainloop()
    
    0
  2. Phil_1857 Messages postés 1883 Date d'inscription   Statut Membre Dernière intervention   169
     
    Holà Noradan,

    Est-ce que ma proposition te convient ? :-)
    0