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 :

Problème de chargement lors d'un appel [Python 3.X]


Sujet :

Tkinter Python

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2021
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2021
    Messages : 7
    Points : 7
    Points
    7
    Par défaut Problème de chargement lors d'un appel
    Tout d'abord bonjour à tous et toutes.

    J'ai codé un petit script qui me permet d'afficher mes comptes clients (je suis chef d'entreprise).
    Je n'arrivais pas à faire en sorte que les lignes de mes treeviews se colorent d'une certaine façon sous conditions et après une recherche, j'ai pu trouver
    le code suivant qui règle ce problème.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    s = ttk.Style ()
    if fTdB.getvar ('tk_patchLevel') == '8.6.9':  # and OS_Name=='nt':
       def fixed_map(option):
       return [elm for elm in s.map ('Treeview', query_opt=option) if elm[:2] != ('!disabled', '!selected')]
    s.map ('Treeview', foreground=fixed_map ('foreground'), background=fixed_map ('background'))
    Je peux ensuite avec un tag.configure, gérer mes background et foreground.
    TOUT fonctionne très bien et j'en suis très content.

    Ayant besoin pour mon travail d'autres script que les comptes clients, j'ai en codé plusieurs (enregistrement, fiche de contact, etc...), et j'ai tout regroupé sous un "launcher",
    qui fonctionne lui aussi très bien, mais (parce qu'il y a un mais...), lorsque j'appelle le compte clients depuis le launcher celui ci s'ouvre et fonctionne parfaitement sauf les conditions sur la coloration...
    et je n'ai aucun message d'erreur...

    Je mets le code du launcher.

    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
     
    # imports
    from tkinter import *
    from AideMPCListeClients import *
    from AideMPCInscription import *
    from AideMPCTdB import *
    from AideMPCPrefs import *
    from AideMPCPlanning import *
     
     
     
    root = Tk()
     
     
    root.title ("Bureau")
     
     
    L=root.winfo_screenwidth()
    l=root.winfo_screenheight()
     
    root.geometry ("720x375+%d+%d" %(L/2-360,l/2-185))
    lblTitlte = Label (root, text="Bureau", font=("Arial", 24), bg="darkblue", fg="white")
    lblTitlte.place (x=0, y=0, width=240)
     
     
    photo_TdB = PhotoImage(file = 'graphique-histogramme.png')
    ButTdB = Button(root, image=photo_TdB, text='TdB', command=FenTabdeBord)
    ButTdB.place(x=380, y=205, height=110, width=110)
     
     
    ButQuit = Button(root, text="Quitter", bg="darkblue", fg="yellow", command=root.destroy)
    ButQuit.place(x=645, y=345, width=75, height=30)
     
     
    root.mainloop()
    J'ajoute également le script du compte client.

    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
     
    from datetime import *
    from tkinter import *
    from tkinter import messagebox
    from tkinter import ttk
     
     
     
    # Tableau de bord
    def FenTabdeBord():
            def Affiche_lancement():
            # Afficher AT du mois en cours
               anneeAT = Entry_AnneeAT.get ()
               moisAT = ListeMoisAT.get ()
               Type1 = "AT"
               conn = sqlite3.connect ('TableauDeBord.db')
               cur = conn.cursor ()
               select = cur.execute ("SELECT * FROM TdB WHERE Année=? AND Mois=? AND RDV=? ORDER BY Date ASC",
                                  (anneeAT, moisAT, Type1,))
               s = ttk.Style ()
               if fTdB.getvar ('tk_patchLevel') == '8.6.9':  # and OS_Name=='nt':
                 def fixed_map(option):
                     return [elm for elm in s.map ('Treeview', query_opt=option) if elm[:2] != ('!disabled', '!selected')]
     
                s.map ('Treeview', foreground=fixed_map ('foreground'), background=fixed_map ('background'))
     
               for x in tree_TdB.get_children ():
                   tree_TdB.delete (x)
               for row in cur.fetchall ():
                   if row[10] == "0":
                       tree_TdB.insert ('', END, value=row, tags=['even'])
                   else:
                       tree_TdB.insert ('', END, value=row, tags=['odd'])
     
               tree_TdB.tag_configure ("even", foreground="black", background="pink")
               tree_TdB.tag_configure ("odd", foreground="black", background="white")
     
               conn.close ()
     
            locale.setlocale (locale.LC_TIME, '')
            fTdB = Tk()
            fTdB.title (' Tableau de bord ')
            fTdB.geometry ('1450x900+%d+%d' % (55, 55))
            List_Tdb = []  # enregistre l'element selectionné
     
            oTdB = ttk.Notebook (fTdB)
            oTdB.place (x=5, y=5, width=1420, height=870)
            oAT = ttk.Frame (oTdB)
            oAT.pack ()
            oB = ttk.Frame (oTdB)
            oB.pack ()
     
            oTdB.add (oAT, text=" RDV AT ")
            oTdB.add (oB, text=" RDV Bilan et autres ")
     
     
            ListeMois = ["janvier", "février", "mars", "avril", "mai", "juin", "juillet", "aout", "septembre", "octobre",
                     "novembre", "décembre"]
            year = datetime.now ().strftime ("%Y")  # année actuelle
            month = datetime.now ().strftime ("%B")  # mois actuel
     
            # onglet AT
           ListeMoisAT = ttk.Combobox (oAT, values=ListeMois)
           ListeMoisAT.place (x=140, y=20, width=125)
           ListeMoisAT.set (month)
     
           Entry_AnneeAT = Entry (oAT)
           Entry_AnneeAT.place (x=280, y=20, width=50)
           Entry_AnneeAT.insert (0, year)
     
           BoutOk = Button (oAT, text='Ok', bg="darkblue", fg="yellow", command=Affiche_lancement)
           BoutOk.place (x=360, y=15, width=50)
     
           tree_TdB = ttk.Treeview (oAT, columns=(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15), height=5,
                                 show="headings", style="mystyle.Treeview")
           tree_TdB.place (x=5, y=50, width=1400, height=750)
     
           #je ne mets pas tout le code
     
           Affiche_lancement()
    Vous comprendrez en lisant le code que je ne suis pas un expert (pas forcement de respect des règles de nommage en Python et pas forcement le code le plus efficient) mais ces scripts ne sont utilisés
    que par ma femme et moi-même et n'ont pas vocation à être diffusés.

    Ainsi j'aimerais, si possible, une aide, ou un descriptif de ce qui ne va pas.

    En vous souhaitant une agréable journée, je vous remercie par avance.

  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 776
    Points
    36 776
    Par défaut
    Salut,

    Citation Envoyé par antho28 Voir le message
    Ainsi j'aimerais, si possible, une aide, ou un descriptif de ce qui ne va pas.
    Vous savez ce qui ne va pas puisque vous l'avez décrit

    Pour le reste, vous racontez avoir corrigé un soucis avec les tags des Treeview du à la version 8.6.9 de TCL/Tk livrée avec la version Python 3.7.3.... et le moyen de contournement que vous avez récupéré ne fonctionne que pour cette version là (de TCL/Tk).

    Vous avez 2 problèmes:
    • est-ce que vous utilisez toujours cette version là? On est en 3.10 côté Python et 8.6.12 côté TCL/Tk livré avec....
    • est-ce que le soucis a été corrigé depuis? Faut il toujours "bricoler" pour...


    note: comme vous ne fournissez pas un code permettant de reproduire quoi que ce que ce soit impossible de savoir si c'est ou pas le même problème - c'est vous qui le dites mais on ne peut pas le vérifier... -.

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

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2021
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2021
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    Bonsoir wiztricks.

    Tout d'abord merci d'avoir pris le temps de répondre à ce topic et effectivement la version de python était restée en 3.7
    (version utilisée lors du démarrage de ce projet...).
    Tout est rentré dans l'ordre.

    Cependant j'ai un second soucis (désolé).
    J'ai un script planning.py qui m'affiche un planning (peu de suspens )

    J'ai deux stringvar qui m'affiche la date de début de semaine et la date de fin de semaine.
    Idem, quand je le lance seul tout est bien fonctionnel, mais quand je lance depuis le launcher tout s'affiche, sauf ces stringvar... et
    pourtant les valeurs sont bien définies puisque je les récupère via un print.

    Je vous mets le code du planning

    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
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
     
    import locale
    import sqlite3
    from datetime import *
    from tkinter import *
    from tkinter import ttk
     
     
     
    def FenPlann2():
        locale.setlocale (locale.LC_TIME, '')
        fPlann = Tk ()
        fPlann.title ('Planning  ')
        fPlann.geometry ('1450x900+%d+%d' % (55, 55))
     
        # onglets planning semaine
        n2 = ttk.Notebook (fPlann)
        n2.place (x=5, y=50, width=1850, height=1000)
        fPlann1 = ttk.Frame (n2)
        fPlann1.pack ()
        fPlann2 = ttk.Frame (n2)
        fPlann2.pack ()
        fPlann3 = ttk.Frame (n2)
        fPlann3.pack ()
        n2.add (fPlann1, text=" Lu / Ma ")
        n2.add (fPlann2, text=" Me / Je ")
        n2.add (fPlann3, text=" Ve / Sa ")
     
        ListeDebut = [0, 0]  # contient les dates (L et S) de la semaine actuels
        ListeDebutStr = [0, 0]
     
        datePlannDebut = StringVar ()
     
        datePlannFin = StringVar ()
     
        locale.setlocale (locale.LC_TIME, '')
        Jourtoday = str (datetime.now ().strftime ("%A"))
        # print(Jourtoday)
        if Jourtoday == "dimanche":
            Prem = (date.today () + timedelta (days=1))
            Der = (date.today () + timedelta (days=6))
        if Jourtoday == "samedi":
            Prem = (date.today () - timedelta (days=5))
            Der = (date.today ())
        if Jourtoday == "vendredi":
            Prem = (date.today () - timedelta (days=4))
            Der = (date.today () + timedelta (days=1))
        if Jourtoday == "jeudi":
            Prem = (date.today () - timedelta (days=3))
            Der = (date.today () + timedelta (days=2))
        if Jourtoday == "mercredi":
            Prem = (date.today () - timedelta (days=2))
            Der = (date.today () + timedelta (days=3))
        if Jourtoday == "mardi":
            Prem = (date.today () - timedelta (days=1))
            Der = (date.today () + timedelta (days=4))
        if Jourtoday == "lundi":
            Prem = (date.today ())
            Der = (date.today () + timedelta (days=5))
        PremStr = Prem.strftime ("%a %d %B %y")
        DerStr = Der.strftime ("%a %d %B %y")
        ListeDebut[0] = Prem
        ListeDebut[1] = Der
        ListeDebutStr[0] = PremStr
        ListeDebutStr[1] = DerStr
     
        print (ListeDebutStr[0], ListeDebutStr[1])
     
        datePlannDebut.set (ListeDebutStr[0])
        datePlannFin.set (ListeDebutStr[1])
     
        BoutPlus = Button (fPlann, text="+", bg="darkblue", fg="yellow", font=("Arial", 12))
        BoutPlus.place (x=250, y=15, width=50)
     
        Attente = Button (fPlann, text="Liste d'attente :", bg="darkblue", fg="yellow", font=("Arial", 12))
        Attente.place (x=450, y=570, width=465)
     
        LbldateDebut = Label (fPlann, textvariable=datePlannDebut, font=("Arial", 12))
        LbldateDebut.place (x=430, y=20)
        LbldateFin = Label (fPlann, textvariable=datePlannFin, font=("Arial", 12))
        LbldateFin.place (x=620, y=20)
     
        BoutPrev = Button (fPlann, text="◄", bg="darkblue", fg="yellow", font=("Arial", 12))
        BoutPrev.place (x=380, y=15, width=50)
     
        BoutNext = Button (fPlann, text="►", bg="darkblue", fg="yellow", font=("Arial", 12))
        BoutNext.place (x=780, y=15, width=50)
     
        Boutton_Export_Planning = Button (fPlann, text="Exporter :", bg="darkblue", fg="yellow", font=("Arial", 10))
        Boutton_Export_Planning.place (x=1110, y=15, width=150)
     
        Lbl_Lundi1 = Label (fPlann1, text="Lundi 13h00")
        Lbl_Lundi1.place (x=50, y=10)
        Lbl_Lundi2 = Label (fPlann1, text="Lundi 15h15")
        Lbl_Lundi2.place (x=215, y=10)
        Lbl_Lundi3 = Label (fPlann1, text="Lundi 17h30")
        Lbl_Lundi3.place (x=380, y=10)
     
        tree_Lundi1 = ttk.Treeview (fPlann1, columns=(1, 2, 3), height=5, show="headings", style="mystyle.Treeview")
        tree_Lundi1.place (x=20, y=30, width=160, height=400)
     
        tree_Lundi2 = ttk.Treeview (fPlann1, columns=(1, 2, 3), height=5, show="headings", style="mystyle.Treeview")
        tree_Lundi2.place (x=185, y=30, width=160, height=400)
        tree_Lundi3 = ttk.Treeview (fPlann1, columns=(1, 2, 3), height=5, show="headings", style="mystyle.Treeview")
        tree_Lundi3.place (x=350, y=30, width=160, height=400)
     
        # dimensions des colonnes
        tree_Lundi1.column (1, width=80)
        tree_Lundi1.column (2, width=40)
        tree_Lundi1.column (3, width=5)
        tree_Lundi2.column (1, width=80)
        tree_Lundi2.column (2, width=40)
        tree_Lundi2.column (3, width=5)
        tree_Lundi3.column (1, width=80)
        tree_Lundi3.column (2, width=40)
        tree_Lundi3.column (3, width=5)
     
        # en tete des TreeView
        tree_Lundi1.heading (1, text="Nom")
        tree_Lundi1.heading (2, text="")
        tree_Lundi1.heading (3, text="")
        tree_Lundi2.heading (1, text="Nom")
        tree_Lundi2.heading (2, text="")
        tree_Lundi2.heading (3, text="")
        tree_Lundi3.heading (1, text="Nom")
        tree_Lundi3.heading (2, text="")
        tree_Lundi3.heading (3, text="")
     
        # séparateur
        separateur31 = ttk.Separator (fPlann1, orient="horizontal")
        separateur31.place (relx=0, rely=0.5, relwidth=1, relheight=0.2)
     
        separateur32 = ttk.Separator (fPlann2, orient="horizontal")
        separateur32.place (relx=0, rely=0.5, relwidth=1, relheight=0.2)
     
        separateur33 = ttk.Separator (fPlann3, orient="horizontal")
        separateur33.place (relx=0, rely=0.5, relwidth=1, relheight=0.2)
     
        # Eleves en attente
     
        Lbl_LundiA1 = Label (fPlann1, text="Lundi 13h00")
        Lbl_LundiA1.place (x=50, y=540)
        Lbl_LundiA2 = Label (fPlann1, text="Lundi 15h15")
        Lbl_LundiA2.place (x=215, y=540)
        Lbl_LundiA3 = Label (fPlann1, text="Lundi 17h30")
        Lbl_LundiA3.place (x=380, y=540)
     
     
        # TreeView d'attente
        tree_LundiA1 = ttk.Treeview (fPlann1, columns=(1, 2, 3), height=5, show="headings", style="mystyle.Treeview")
        tree_LundiA1.place (x=20, y=560, width=160, height=155)
        tree_LundiA1.column (1, width=80)
        tree_LundiA1.column (2, width=40)
        tree_LundiA1.column (3, width=5)
        tree_LundiA1.heading (1, text="Nom")
        tree_LundiA1.heading (2, text="")
        tree_LundiA1.heading (3, text="")
        tree_LundiA2 = ttk.Treeview (fPlann1, columns=(1, 2, 3), height=5, show="headings", style="mystyle.Treeview")
        tree_LundiA2.place (x=185, y=560, width=160, height=155)
        tree_LundiA2.column (1, width=80)
        tree_LundiA2.column (2, width=40)
        tree_LundiA2.column (3, width=5)
        tree_LundiA2.heading (1, text="Nom")
        tree_LundiA2.heading (2, text="")
        tree_LundiA2.heading (3, text="")
        tree_LundiA3 = ttk.Treeview (fPlann1, columns=(1, 2, 3), height=5, show="headings", style="mystyle.Treeview")
        tree_LundiA3.place (x=350, y=560, width=160, height=155)
        tree_LundiA3.column (1, width=80)
        tree_LundiA3.column (2, width=40)
        tree_LundiA3.column (3, width=5)
        tree_LundiA3.heading (1, text="Nom")
        tree_LundiA3.heading (2, text="")
        tree_LundiA3.heading (3, text="")
     
     
        fPlann.mainloop ()
     
    #FenPlann2()
    et de nouveau le code du launcher.

    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
     
    from tkinter import *
    from test import *
     
     
     
    root = Tk()
     
    root.title ("Bureau")
     
    L=root.winfo_screenwidth()
    l=root.winfo_screenheight()
     
    root.geometry ("720x375+%d+%d" %(L/2-360,l/2-185))
    lblTitlte = Label (root, text="Aide MPC", font=("Arial", 24), bg="darkblue", fg="white")
    lblTitlte.place (x=0, y=0, width=240)
     
    photo_Plan = PhotoImage(file = 'PlanningV.png')
    ButPlan = Button(root, image=photo_Plan,text='Planning', command=FenPlann2)
    ButPlan.place(x=380, y=60, height=110, width=110)
     
     
    ButQuit = Button(root, text="Quitter", bg="darkblue", fg="yellow", command=root.destroy)
    ButQuit.place(x=645, y=345, width=75, height=30)
     
     
    root.mainloop()
    Merci d'avance pour tous vos retours qui sont toujours clairs et poussent à l'auto-correction.

  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 776
    Points
    36 776
    Par défaut
    Salut,

    Dans planning, ligne 12, remplacez fPlann = Tk () par fPlann = Toplevel(): on n'est pas supposé avoir 2 instances de Tk dans la même application (sans savoir le gérer).

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

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Enseignant
    Inscrit en
    Avril 2021
    Messages
    7
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 38
    Localisation : France, Eure et Loir (Centre)

    Informations professionnelles :
    Activité : Enseignant

    Informations forums :
    Inscription : Avril 2021
    Messages : 7
    Points : 7
    Points
    7
    Par défaut
    Encore une fois merci à vous wiztricks.

    Cela semble si simple.
    C'est là que l'on voit l'expérience, sur un "simple détail"...

    En tous cas, merci d'avoir pris le temps de me lire, m'aiguiller et m'apprendre.

    Je vous souhaite une agréable fin de soirée.

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

Discussions similaires

  1. problème d'arguments lors de l'appelle d'un web service
    Par hammag dans le forum Services Web
    Réponses: 1
    Dernier message: 24/06/2008, 17h30
  2. Réponses: 7
    Dernier message: 05/06/2008, 14h37
  3. Réponses: 4
    Dernier message: 06/04/2008, 11h54
  4. Problème de linking lors de l'appel d'un .cpp
    Par beegees dans le forum C++
    Réponses: 4
    Dernier message: 31/03/2008, 20h05
  5. Problème de variable lors d'1 appel de fonction PHP
    Par kriekbellevue dans le forum Général JavaScript
    Réponses: 14
    Dernier message: 14/02/2006, 17h49

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