IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

Création Listview [Python 3.X]


Sujet :

Tkinter Python

  1. #1
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    441
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 441
    Points : 111
    Points
    111
    Par défaut Création Listview
    Bonjour,

    Je souhaite créer une Listview dans laquelle je souhaite stocker les fichiers trouvés dans un dossier.

    Je n'arrive pas à créer une Listview à mes besoins:
    -Une listview avec scrollbar vertical,
    -Une listview extensible en largeur et hauteur (en fonction si plein ecran ou non).

    Merci pour vos réponses.

    Ci-joint mon code actuel:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    self.Files_Listview = Treeview(main_window)
            self.Files_Listview["columns"]=('name', 'date', 'size', 'path')
            self.Files_Listview.column('name', width=100)
            self.Files_Listview.column('date', width=100)
            self.Files_Listview.column('size', width=100)
            self.Files_Listview.heading('name', text='Nom')
            self.Files_Listview.heading('date', text='Date')
            self.Files_Listview.heading('size', text='Taille')
            self.Files_Listview.heading('path', text='Chemin')
            self.Files_Listview.place(x=5, y=390)

  2. #2
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 287
    Points : 36 778
    Points
    36 778
    Par défaut
    Salut,

    Citation Envoyé par Supernatural Voir le message
    Je n'arrive pas à créer une Listview à mes besoins:
    -Une listview avec scrollbar vertical,
    -Une listview extensible en largeur et hauteur (en fonction si plein ecran ou non).
    Le widget s'appelle ttk.Treeview... et votre code ne montre rien de ce que vous avez essayé de faire côté scrollbar ou extensibilité. Pourtant, comme il s'agit d'opérations de base, un peu de recherche sur Internet vous permettrait de récupérer le code d'exemples que vous pourriez adapter.
    Qu'en pensez vous?

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  3. #3
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    441
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 441
    Points : 111
    Points
    111
    Par défaut
    Je dépoussière ce post ^^, bon je suis arrivé à faire apparaître les scrollbar, mais j'ai deux soucis:

    1./ La scrollbar de ma ListBox n'est pas collée à ma ListBox,
    2./ Je n'arrive toujours pas à faire suivre la largeur de ma ListView (tree) selon la taille de ma fenêtre principale...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    from configparser import ConfigParser
    import tkinter as tk
    from tkinter import *
    from tkinter import ttk
    from tkinter.ttk import *
    from tkinter import font
    from tkinter import Listbox
    import ftplib
    import os
    from datetime import datetime, timedelta
    from pytz import timezone
    import string
    import array
    from io import BytesIO
    import numpy as np
    from mpl_toolkits.axes_grid1 import host_subplot
    import matplotlib.pyplot as plt
    from collections import Counter
    from tkinter import messagebox
     
    #Graphical Interface test
    class Application(ttk.Frame):
     
        def __init__(self, main_window):
            super().__init__(main_window)
            main_window.title("MyFirtsInterfaceWithPython3.x")
            #Size of my window interface
            w = 1300
            h = 700
     
            ws = main_window.winfo_screenwidth()
            hs = main_window.winfo_screenheight()
            x = (ws/2) - (w/2)
            y = (hs/2) - (h/2)
     
            main_window.geometry('%dx%d+%d+%d' % (w, h, x, y))
            self.GraphicalInterface()
     
        def GraphicalInterface(self):
            #Define font
            Myfont=font.Font(main_window, family='Courier new', size='10')
     
            labelSelectline = tk.Label(main_window, text="Select a line:", anchor="w", font=Myfont)
            labelSelectline.grid(row=0, column=0, padx=10, sticky=NW)
     
            COMBOBOX_LINE = ttk.Combobox(main_window, values=("A", "B", "C", "D"), state='readonly', font=Myfont)
            COMBOBOX_LINE.grid(row=1, column=0, padx=10, sticky=NW)
     
            labelSelectCell = tk.Label(main_window, text="Select a cell:", anchor="w", font=Myfont)
            labelSelectCell.grid(row=2, column=0, padx=10, sticky=NW)
     
            Cell_listbox = Listbox(main_window, font=Myfont, width=22)
            Cell_listbox.grid(row=3, column=0, padx=10, sticky=NW)
     
            #Create a vertical scrollbar to the right of the listbox
            yscroll = tk.Scrollbar(command=Cell_listbox.yview, orient=tk.VERTICAL)
            yscroll.grid(row=3, column=0, padx=10, pady=10, sticky=NS+NE)
            Cell_listbox.configure(yscrollcommand=yscroll.set)
     
            #Filling
            i=0
            while i<30:
                Cell_listbox.insert(END, i)
                i+=1
     
            #ListView
            tree = ttk.Treeview(main_window)
            tree.grid(row=4, column=0, sticky=EW, padx=10, pady=10)
            style = ttk.Style()
            style.configure("Treeview.Heading", font=('Courier new', 10))
            style.configure("Treeview", font=('Courier new', 10))
            tree["columns"] = ("Column_1","Column_2", "Column_3", "Column_4")
            tree.column("#0",       width=230, minwidth=0, stretch=tk.YES)
            tree.column("Column_1", width=175, minwidth=0, stretch=tk.YES)
            tree.column("Column_2", width=70,  minwidth=0, stretch=tk.YES)
            tree.column("Column_3", width=450, minwidth=0, stretch=tk.YES)
            tree.column("Column_4", width=150, minwidth=0, stretch=tk.YES)
     
            tree.heading("#0",       text="Nom")
            tree.heading("Column_1", text="Date")
            tree.heading("Column_2", text="Taille")
            tree.heading("Column_3", text="Chemin")
            tree.heading("Column_4", text="Port FTP")
     
            #Create a vertical scrollbar to the right of the ListView (tree)
            tree_yscroll = tk.Scrollbar(command=tree.yview, orient=tk.VERTICAL)
            tree_yscroll.grid(row=4, column=0, pady=10, sticky=NS+NE)
            tree.configure(yscrollcommand=yscroll.set)
     
     
     
     
    main_window = tk.Tk()
    app         = Application(main_window)
    app.mainloop()

  4. #4
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 287
    Points : 36 778
    Points
    36 778
    Par défaut
    Salut,

    Il faut commencer par réduire votre code à une Frame, une Treeview et une ou deux Scrollbar en essayant d'abord de comprendre le tuto. d'effbot sur le sujet.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  5. #5
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    441
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 441
    Points : 111
    Points
    111
    Par défaut
    Oui j'ai déjà entre-aperçu , mais ce qui est peinible avec Python, c'est le placment des widgets... pack, grid, on ne sait jamais sur quel pied danser...

    Donc quel placement utiliser pour pouvoir utiliser au mieux TOUS les widgets sans avoir à être confronter à ce problème???

  6. #6
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 287
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 287
    Points : 36 778
    Points
    36 778
    Par défaut
    Citation Envoyé par Supernatural Voir le message
    Donc quel placement utiliser pour pouvoir utiliser au mieux TOUS les widgets sans avoir à être confronter à ce problème???
    S'il y a plusieurs gestionnaires de "placement", c'est qu'ils ont leur utilité en fonction du rendu (ce qui va s'afficher) à obtenir et du tas de widgets qu'il va falloir disposer...
    De toutes façons, au plus ce qui devra être affiché sera complexe, au plus il va falloir découper la chose en Frames sur lesquelles vous allez positionner une partie des widgets via "grid" ou "pack" puis afficher le tout.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  7. #7
    Membre régulier
    Homme Profil pro
    Touche à tout
    Inscrit en
    Mai 2017
    Messages
    441
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Allier (Auvergne)

    Informations professionnelles :
    Activité : Touche à tout

    Informations forums :
    Inscription : Mai 2017
    Messages : 441
    Points : 111
    Points
    111
    Par défaut
    Ok merci, j'ai lu et j'ai vaincu ^^

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Création ListView
    Par flyer74 dans le forum Composants graphiques
    Réponses: 7
    Dernier message: 23/03/2012, 18h11
  2. La création de colonnes dans une ListView en QML
    Par dourouc05 dans le forum Qt Quick
    Réponses: 0
    Dernier message: 11/01/2011, 14h49
  3. Création d'une LISTVIEW
    Par mulfycrowh dans le forum Visual C++
    Réponses: 4
    Dernier message: 07/10/2009, 10h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo