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

Python Discussion :

Python Tk recuperer la valeur d'une ligne dans une liste


Sujet :

Python

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France, Marne (Champagne Ardenne)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 4
    Par défaut Python Tk recuperer la valeur d'une ligne dans une liste
    Bonjour à tous
    avec bien du mal j'ai adapté un script pour un usage personnel.
    Celui-ci affiche deux listes mais dans la deuxième liste je voudrais que ne s'affiche que ce qui est relatif au focus de la ligne de la première liste
    excusez moi si je ne suis pas très clair.
    je vous donne le script:

    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    from tkinter import *
    from tkinter import ttk, messagebox
    from contact import contact
    from appareil import appareil
    import sqlite3
    import os
    import threading
     
     
    class Reparation:
        def __init__(self, root_win):
            self.root = root_win
            self.root.geometry("2000x700+0+0")
            self.root.title("Gestion des réparations")
            self.root.config(bg="white")
     
            # Titre de l'écran
            title = Label(self.root, text="Tableau de Bord", font=("Lato", 26, "bold"), bg="white", fg="#343A40", anchor="w", padx=20) # peut ajouter une ancre ici au centre gauche
            title.place(x=200, y=0, relwidth=1, height=70)
     
            # bouton de déconnexion
            logout_btn = Button(self.root, text="Quitter", command=self.logout, font=("Lato", 11, "bold"), bd=0, bg="#F66B0E", fg="white")
            logout_btn.place(x=1180, y=10, height=40, width=120)
     
            # Menu
            menu_frame = Frame(self.root, bd=0, bg="#23282c", relief=RIDGE)
            menu_frame.place(x=0, y=0, width=200, height=400, relheight=1)
     
            menu_label = Label(menu_frame, text="Menu", font=("Lato", 15, "bold"), fg="#313552", bg="#23ba9b")
            menu_label.pack(side=TOP, fill=X)
     
            contacts_btn = Button(menu_frame, text="contact", command=self.contact, font=("Lato", 14, "normal"), bg="#23282c", fg="#a7acb2", bd=0, cursor="hand2")
            contacts_btn.pack(side=TOP, fill=X)
            appareils_btn = Button(menu_frame, text="appareils", command=self.appareils, bg="#23282c", font=("Lato", 14, "normal"), fg="#a7acb2", bd=0, cursor="hand2")
            appareils_btn.pack(side=TOP, fill=X)
     
            # contact list
            contact_list_frame = Frame(self.root, bd=3, relief=RIDGE)
            contact_list_frame.place (x=220, y=100, width=1700, height=250)  #contact_list_frame.place(x=220, y=100, width=1100, height=250)
     
            scroll_y = Scrollbar(contact_list_frame, orient=VERTICAL)
            scroll_x = Scrollbar(contact_list_frame, orient=HORIZONTAL)
            scroll_x.pack(side=BOTTOM, fill=X)
            scroll_y.pack(side=RIGHT, fill=Y)
     
            contact_list_columns = ("id", "nom", "prenom", "adresse", "ville", "tel_fixe", "tel_mobile", "mel", "renseignements")
            self.contact_list_table = ttk.Treeview(contact_list_frame, columns=contact_list_columns, yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set)
            self.contact_list_table.pack(fill=BOTH, expand=1)
            scroll_x.config(command=self.contact_list_table.xview)
            scroll_y.config(command=self.contact_list_table.yview)
     
            self.contact_list_table.heading("id", text="ID")
            self.contact_list_table.heading("nom", text="Nom")
            self.contact_list_table.heading("prenom", text="Prenom")
            self.contact_list_table.heading("adresse", text="Adresse")
            self.contact_list_table.heading("ville", text="Ville")
            self.contact_list_table.heading("tel_fixe", text="Tel_fixe")
            self.contact_list_table.heading("tel_mobile", text="Tel_mobile")
            self.contact_list_table.heading("mel", text="Mel")
            self.contact_list_table.heading("renseignements", text="Renseignemets")
            self.contact_list_table["show"] = "headings"
     
            self.contact_list_table.column("id", width=10)
            self.contact_list_table.column("nom", width=100)
            self.contact_list_table.column("prenom", width=100)
            self.contact_list_table.column("adresse", width=110)
            self.contact_list_table.column("ville", width=100)
            self.contact_list_table.column("tel_fixe", width=100)
            self.contact_list_table.column("tel_mobile", width=100)
            self.contact_list_table.column("mel", width=100)
            self.contact_list_table.column("renseignements", width=100)
     
     
            # appareils list
            appareils_list_column = Frame(self.root, bd=3, relief=RIDGE)
            appareils_list_column.place(x=220, y=360, width=1700, height=250)  #appareils_list_column.place(x=220, y=350, width=1100, height=250)
     
            scroll_y = Scrollbar(appareils_list_column, orient=VERTICAL)
            scroll_x = Scrollbar(appareils_list_column, orient=HORIZONTAL)
            scroll_x.pack(side=BOTTOM, fill=X)
            scroll_y.pack(side=RIGHT, fill=Y)
     
            appareils_list_columns = ("id", "nom","type", "modele", "panne", "solution", "prix", "id_contact", "date")
            self.appareils_list_table = ttk.Treeview(appareils_list_column, columns=appareils_list_columns, yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set)
            self.appareils_list_table.pack(fill=BOTH, expand=1)
            scroll_x.config(command=self.appareils_list_table.xview)
            scroll_y.config(command=self.appareils_list_table.yview)
     
            self.appareils_list_table.heading("id", text="ID") 
            self.appareils_list_table.heading("nom", text="Nom")
            self.appareils_list_table.heading("type", text="Type")
            self.appareils_list_table.heading("modele", text="Modele")
            self.appareils_list_table.heading("panne", text="panne")
            self.appareils_list_table.heading("solution", text="Solution")
            self.appareils_list_table.heading("prix", text="Prix")
            self.appareils_list_table.heading("id_contact", text="id_contact")
            self.appareils_list_table.heading("date", text="Date")
            self.appareils_list_table["show"] = "headings"
     
            self.appareils_list_table.column("id", width=10)
            self.appareils_list_table.column("nom", width=100)
            self.appareils_list_table.column("type", width=100)
            self.appareils_list_table.column("modele", width=100)
            self.appareils_list_table.column("panne", width=100)
            self.appareils_list_table.column("solution", width=100)
            self.appareils_list_table.column("prix", width=100)
            self.appareils_list_table.column("id_contact", width=100)
            self.appareils_list_table.column("date", width=100)
     
     
            #footer
            footer = Label(self.root, text="will write footer here later", font=("Lato", 15, "normal"), bg="#2EB086", fg="#313552") # may add anchor here to center left
            footer.place(x=0, y=670, relwidth=1, height=30)
     
            #self.update_content()
            self.show_contact()
            self.show_appareils()
            # ========================================================
     
     
     
        def contact(self):
            self.new_window = Toplevel(self.root)
            self.cont_manager = contact(self.new_window)
     
        def appareils(self):
            self.new_window = Toplevel(self.root)
            self.app_manager = appareil(self.new_window)
     
     
        def logout(self):
            self.root.destroy()
     
     
        def show_contact(self):
            con = sqlite3.connect("reparation.db")
            cur = con.cursor()
            try:
                cur.execute("SELECT * FROM contacts")
                rows = cur.fetchall()
                self.contact_list_table.delete(*self.contact_list_table.get_children())
                for row in rows:
                    self.contact_list_table.insert('',END,values=row)
            except Exception as ex:
                messagebox.showerror("Erreur", f"Erreur: {str(ex)}", parent=self.root)
     
        def show_appareils(self):
            con = sqlite3.connect("reparation.db")
            cur = con.cursor()
            try:
                cur.execute("SELECT cont.id, cont.nom, app.type, app.modele, app.panne, app.solution, app.prix, app.ID_contact, app.date FROM contacts cont JOIN appareils app ON cont.id=app.ID_contact ")  # SELECT ls.invoice, p.name, ls.price, ls.qty FROM line_sale ls JOIN product p ON ls.product_id=p.id
                rows = cur.fetchall()
                self.appareils_list_table.delete(*self.appareils_list_table.get_children())
                for row in rows:
                    self.appareils_list_table.insert('',END,values=row)
            except Exception as ex:
                messagebox.showerror("Erreur", f"Erreur: {str(ex)}", parent=self.root)
     
     
    if __name__ == "__main__":
        root = Tk()
        system = Reparation (root)
        root.mainloop()

  2. #2
    Expert confirmé
    Avatar de popo
    Homme Profil pro
    Analyste programmeur Delphi / C#
    Inscrit en
    Mars 2005
    Messages
    2 972
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Analyste programmeur Delphi / C#
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mars 2005
    Messages : 2 972
    Par défaut
    Sachant que la syntaxe de Python est basée sur l'indentation, tu aurais pu faire un effort de mise en forme.

  3. #3
    Expert éminent
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 752
    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 752
    Par défaut
    Salut,

    Déjà après avoir posté votre code, vous avez du vous apercevoir que les indentations ont disparu. Ce qui est dommage car avec Python, c'est juste illisible.

    Ceci dit:

    Citation Envoyé par delcano Voir le message
    Celui-ci affiche deux listes mais dans la deuxième liste je voudrais que ne s'affiche que ce qui est relatif au focus de la ligne de la première liste
    Dans le votre code, il y a des widgets qui affichent des données.... Peut être vous voulez parler des Treeview?
    La ligne d'un Treeview est sélectionnée ou pas mais le focus, c'est autre chose.

    Citation Envoyé par delcano Voir le message
    excusez moi si je ne suis pas très clair.
    Le code n'est pas fonctionnel (donc on ne peut pas trop voir à quoi peut correspondre ce que vous racontez), la description technique n'est pas assez précise pour rattraper le coup... Vous excuser ne sert à rien.

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

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France, Marne (Champagne Ardenne)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 4
    Par défaut
    Citation Envoyé par wiztricks Voir le message
    Salut,
    Déjà après avoir posté votre code, ...
    - W
    Merci pour votre répons
    en aparté je ne m'excusait pas ...je vous demandais de m'excuser

  5. #5
    Membre Expert
    Profil pro
    Inscrit en
    Septembre 2010
    Messages
    1 545
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Septembre 2010
    Messages : 1 545
    Par défaut
    le Treeview affiche une arborescence, donc pourquoi ne pas mettre les relatifs à chaque entrée en enfant de ces entrées ?

    Sinon il faut binder l'événement virtuel "<<TreeviewSelect>>" que génère le Treeview pour appeler une fonction de mise à jour du 2nd Treeview en utilisant la méthode Treeview.focus() ou Treeview.selection() pour récupérer l'élément sélectionné du 1er Treeview

    https://docs.python.org/3/library/tk....html#treeview

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Janvier 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Localisation : France, Marne (Champagne Ardenne)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 4
    Par défaut
    voici avec l'indentation
    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
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    from tkinter import *
    from tkinter import ttk, messagebox
    from contact import contact
    from appareil import appareil
    import sqlite3
    import os
    import threading
     
     
    class Reparation:
        def __init__(self, root_win):
            self.root = root_win
            self.root.geometry("2000x700+0+0")
            self.root.title("Gestion des réparations")
            self.root.config(bg="white")
     
            # Titre de l'écran
            title = Label(self.root, text="Tableau de Bord", font=("Lato", 26, "bold"), bg="white", fg="#343A40", anchor="w", padx=20) # peut ajouter une ancre ici au centre gauche
            title.place(x=200, y=0, relwidth=1, height=70)
     
            # bouton de déconnexion
            logout_btn = Button(self.root, text="Quitter", command=self.logout, font=("Lato", 11, "bold"), bd=0, bg="#F66B0E", fg="white")
            logout_btn.place(x=1180, y=10, height=40, width=120)
     
            # Menu
            menu_frame = Frame(self.root, bd=0, bg="#23282c", relief=RIDGE)
            menu_frame.place(x=0, y=0, width=200, height=400, relheight=1)
     
            menu_label = Label(menu_frame, text="Menu", font=("Lato", 15, "bold"), fg="#313552", bg="#23ba9b")
            menu_label.pack(side=TOP, fill=X)
     
            contacts_btn = Button(menu_frame, text="contact", command=self.contact, font=("Lato", 14, "normal"), bg="#23282c", fg="#a7acb2", bd=0, cursor="hand2")
            contacts_btn.pack(side=TOP, fill=X)
            appareils_btn = Button(menu_frame, text="appareils", command=self.appareils, bg="#23282c", font=("Lato", 14, "normal"), fg="#a7acb2", bd=0, cursor="hand2")
            appareils_btn.pack(side=TOP, fill=X)
     
            # contact list
            contact_list_frame = Frame(self.root, bd=3, relief=RIDGE)
            contact_list_frame.place (x=220, y=100, width=1700, height=250)  #contact_list_frame.place(x=220, y=100, width=1100, height=250)
     
            scroll_y = Scrollbar(contact_list_frame, orient=VERTICAL)
            scroll_x = Scrollbar(contact_list_frame, orient=HORIZONTAL)
            scroll_x.pack(side=BOTTOM, fill=X)
            scroll_y.pack(side=RIGHT, fill=Y)
     
            contact_list_columns = ("id", "nom", "prenom", "adresse", "ville", "tel_fixe", "tel_mobile", "mel", "renseignements")
            self.contact_list_table = ttk.Treeview(contact_list_frame, columns=contact_list_columns, yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set)
            self.contact_list_table.pack(fill=BOTH, expand=1)
            scroll_x.config(command=self.contact_list_table.xview)
            scroll_y.config(command=self.contact_list_table.yview)
     
            self.contact_list_table.heading("id", text="ID")
            self.contact_list_table.heading("nom", text="Nom")
            self.contact_list_table.heading("prenom", text="Prenom")
            self.contact_list_table.heading("adresse", text="Adresse")
            self.contact_list_table.heading("ville", text="Ville")
            self.contact_list_table.heading("tel_fixe", text="Tel_fixe")
            self.contact_list_table.heading("tel_mobile", text="Tel_mobile")
            self.contact_list_table.heading("mel", text="Mel")
            self.contact_list_table.heading("renseignements", text="Renseignemets")
            self.contact_list_table["show"] = "headings"
     
            self.contact_list_table.column("id", width=10)
            self.contact_list_table.column("nom", width=100)
            self.contact_list_table.column("prenom", width=100)
            self.contact_list_table.column("adresse", width=110)
            self.contact_list_table.column("ville", width=100)
            self.contact_list_table.column("tel_fixe", width=100)
            self.contact_list_table.column("tel_mobile", width=100)
            self.contact_list_table.column("mel", width=100)
            self.contact_list_table.column("renseignements", width=100)
     
     
            # appareil list
            appareil_list_column = Frame(self.root, bd=3, relief=RIDGE)
            appareil_list_column.place(x=220, y=360, width=1700, height=250)  #appareil_list_column.place(x=220, y=350, width=1100, height=250)
     
            scroll_y = Scrollbar(appareil_list_column, orient=VERTICAL)
            scroll_x = Scrollbar(appareil_list_column, orient=HORIZONTAL)
            scroll_x.pack(side=BOTTOM, fill=X)
            scroll_y.pack(side=RIGHT, fill=Y)
     
            appareil_list_columns = ("id_contact", "type", "modele", "panne", "solution", "prix", "date")
            self.appareil_list_table = ttk.Treeview(appareil_list_column, columns=appareil_list_columns, yscrollcommand=scroll_y.set, xscrollcommand=scroll_x.set)
            self.appareil_list_table.pack(fill=BOTH, expand=1)
            scroll_x.config(command=self.appareil_list_table.xview)
            scroll_y.config(command=self.appareil_list_table.yview)
     
            self.appareil_list_table.heading("id_contact", text="id_contact")
            self.appareil_list_table.heading("type", text="Type")
            self.appareil_list_table.heading("modele", text="Modele")
            self.appareil_list_table.heading("panne", text="panne")
            self.appareil_list_table.heading("solution", text="Solution")
            self.appareil_list_table.heading("prix", text="Prix")
            self.appareil_list_table.heading("date", text="Date")
            self.appareil_list_table["show"] = "headings"
     
            self.appareil_list_table.column("id_contact", width=20)
            self.appareil_list_table.column("type", width=100)
            self.appareil_list_table.column("modele", width=100)
            self.appareil_list_table.column("panne", width=100)
            self.appareil_list_table.column("solution", width=100)
            self.appareil_list_table.column("prix", width=100)
            self.appareil_list_table.column("date", width=100)
     
     
            #footer
            footer = Label(self.root, text="will write footer here later", font=("Lato", 15, "normal"), bg="#2EB086", fg="#313552") # may add anchor here to center left
            footer.place(x=0, y=670, relwidth=1, height=30)
     
            #self.update_content()
            self.show_contact()
     
     
            self.show_appareil()
            # ========================================================
     
     
        def contact(self):
            self.new_window = Toplevel(self.root)
            self.cont_manager = contact(self.new_window)
     
     
     
        def appareils(self):
            self.new_window = Toplevel(self.root)
            self.app_manager = appareil(self.new_window)
     
     
        def logout(self):
            self.root.destroy()
     
     
        def show_contact(self):
            con = sqlite3.connect("reparation.db")
            cur = con.cursor()
            try:
                cur.execute("SELECT * FROM contacts")
                rows = cur.fetchall()
                self.contact_list_table.delete(*self.contact_list_table.get_children())
                for row in rows:
                    self.contact_list_table.insert('',END,values=row)
            except Exception as ex:
                messagebox.showerror("Erreur", f"Erreur: {str(ex)}", parent=self.root)
     
     
     
        def show_appareil(self):
            con = sqlite3.connect("reparation.db")
            cur = con.cursor()
            try:
                cur.execute("SELECT ID_contact, Type, Modele, Panne, Solution, prix, Date FROM appareils INNER JOIN contacts ON  appareils.ID_contact = contacts.id " ) 
                rows = cur.fetchall()
                self.appareil_list_table.delete(*self.appareil_list_table.get_children())
                for row in rows:
                    self.appareil_list_table.insert('',END,values=row)
            except Exception as ex:
                messagebox.showerror("Erreur", f"Erreur: {str(ex)}", parent=self.root)
     
     
    if __name__ == "__main__":
        root = Tk()
        system = Reparation (root)
        root.mainloop()

  7. #7
    Expert confirmé
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    4 063
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 4 063
    Par défaut
    Bonjour,

    Citation Envoyé par delcano
    avec bien du mal j'ai adapté un script pour un usage personnel.
    Il est souvent préférable pour un débutant de créer soit même son script, car c'est mieux comprendre ce qui a été codé et surtout pourquoi on le code.

Discussions similaires

  1. [PYTHON/FORTRAN] Recupérer la valeur d'une variable de COMMON FORTRAN vers PYTHON
    Par squallmrs dans le forum Interfaçage autre langage
    Réponses: 0
    Dernier message: 06/06/2012, 16h51
  2. [SQL] Problème de récupération des valeurs d'une liste multiple en php
    Par BOLARD dans le forum PHP & Base de données
    Réponses: 1
    Dernier message: 01/05/2006, 00h29
  3. [Ajax] Recupérer la valeur d'une liste
    Par Kaimann dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 23/02/2006, 18h22
  4. récupérer la valeur d'une liste à l'envoi d'un formulaire
    Par grinder59 dans le forum Général JavaScript
    Réponses: 1
    Dernier message: 24/01/2006, 10h49
  5. récupérer la valeur d'une liste déroulante dynamique
    Par grinder59 dans le forum Général JavaScript
    Réponses: 21
    Dernier message: 23/01/2006, 17h51

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