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 :

Affichage d'images et bizarreté


Sujet :

Tkinter Python

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Médecin
    Inscrit en
    Avril 2017
    Messages
    33
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 62
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Médecin
    Secteur : Santé

    Informations forums :
    Inscription : Avril 2017
    Messages : 33
    Par défaut Affichage d'images et bizarreté
    Bonsoir,
    Je reviens vers vous pour un problème que je ne m'explique pas, toujours dans le même cadre de mon appli cabinet (cf https://www.developpez.net/forums/d2...s-ineffective/)
    Pour chaque personne qui vient, je stocke des images, principalement de l'examen des cordes vocales. Les images sont référencées dans une table avec liaison sur l'id de chaque personne, j'affiche la liste dans un Treeview et voudrais en cliquant sur le nom d'une photo la voir s'afficher dans un canvas à côté.
    La base pour afficher des images ne pose pas de problème (je vous ai épargné les photos de cordes vocales et ai mis des persos Disney à la place, ça évitera les cris d'horreur !
    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
    import tkinter as tk
    from tkinter import ttk
    from PIL import Image,ImageTk
     
    FenetreBC_root = tk.Tk()
    FenetreBC_root.geometry('1280x777')
    FenetreBC_root.title('Cabinet de Phoniatrie Bruno')
    FenetreGestion_Photo = ttk.Frame(FenetreBC_root)
    FenetreGestion_Photo.place(x = 0, y = 0, width = 1280, height = 877)
     
     
    # Construction Table à onglets
    OngletAffichageBase = ttk.Notebook(FenetreGestion_Photo)
    OngletAffichageBase.place(x = 50, y = 100, width = 800, height = 500)
    Onglet1 = ttk.Frame(OngletAffichageBase)
    Onglet1.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet1, text = "Etat-civil")
    Onglet2 = ttk.Frame(OngletAffichageBase)
    Onglet2.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet2, text = "Diagnostic et correspondants")
    Onglet3 = ttk.Frame(OngletAffichageBase)
    Onglet3.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet3, text = "Actes")
    Onglet4 = ttk.Frame(OngletAffichageBase)
    Onglet4.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet4, text = "Courriers")
    Onglet5 = ttk.Frame(OngletAffichageBase)
    Onglet5.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet5, text = "Photos")
     
    # Création du canvas
    chAffPhoto= tk.Canvas(Onglet5, width= 300, height= 300)
    chAffPhoto.place(x=40,y=40)
     
    # Chargement d'une des images
    imagePerso= ImageTk.PhotoImage(Image.open("Donald300.jpg"))
     
    # Mise en place de l'image dans le Canvas
    chAffPhoto.create_image(10,10,anchor=tk.NW,image=imagePerso)
     
    FenetreBC_root.mainloop()
    Ça se complique quand je mets les onglets et le Treeview dans l'onglet 'Photos', l'affichage se fait par l'appel d'une fonction depuis l'événement de sélection dans le Treeview, et là aucune photo affichée

    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
    import tkinter as tk
    from tkinter import ttk
    from PIL import Image,ImageTk
     
    listePersos=[("Mickey","Mickey300.jpg"),("Donald","Donald300.jpg"),("Picsou","Picsou300.jpg")]
     
    def affichPhoto(actionRealisee):
        """
        """     
        # Récupération des données du perso sélectionné dans le TreeView
        itemSelectionne = listePhotos.focus()
        refPhoto = listePhotos.item(itemSelectionne, 'values')
        # Chemin et nom de l'image
        cheminImage=str(refPhoto[1])
        # Construction de l'image
        trPhotoAAff = ImageTk.PhotoImage(Image.open(cheminImage))
        cnAffPhoto.create_image(10,10,anchor=tk.NW,image=trPhotoAAff)
     
    FenetreBC_root = tk.Tk()
    FenetreBC_root.geometry('1280x777')
    FenetreBC_root.title('Cabinet de Phoniatrie Bruno')
    FenetreGestion_Photo = ttk.Frame(FenetreBC_root)
    FenetreGestion_Photo.place(x = 0, y = 0, width = 1280, height = 877)
     
     
    # Construction Table à onglets
    OngletAffichageBase = ttk.Notebook(FenetreGestion_Photo)
    OngletAffichageBase.place(x = 50, y = 100, width = 800, height = 500)
    Onglet1 = ttk.Frame(OngletAffichageBase)
    Onglet1.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet1, text = "Etat-civil")
    Onglet2 = ttk.Frame(OngletAffichageBase)
    Onglet2.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet2, text = "Diagnostic et correspondants")
    Onglet3 = ttk.Frame(OngletAffichageBase)
    Onglet3.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet3, text = "Actes")
    Onglet4 = ttk.Frame(OngletAffichageBase)
    Onglet4.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet4, text = "Courriers")
    Onglet5 = ttk.Frame(OngletAffichageBase)
    Onglet5.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet5, text = "Photos")
     
    # Liste multicolonnes des photos
    colonnes = ('IdPerso','NomFichier')
    listePhotos=ttk.Treeview(Onglet5, columns=colonnes, show='')
    # Constitutions des colonnes, avec entêtes non affichées
    listePhotos.heading('#0', text='')
    listePhotos.heading('IdPerso', text='Identification du perso')
    listePhotos.heading('NomFichier', text="Nom du fichier")
    listePhotos.column('#0', minwidth=0,width=0, stretch=tk.NO)
    listePhotos.column('IdPerso', minwidth=0,width=130)
    listePhotos.column('NomFichier', minwidth=0,width=0, stretch=tk.NO)
    listePhotos.place(x = 440, y = 100, width = 210, height = 260)
    listePhotos.bind("<<TreeviewSelect>>", affichPhoto)
    # Rajout d'une barre de défilement vertical
    photVertScrlbar = ttk.Scrollbar(listePhotos,orient ="vertical",command = listePhotos.yview)
    photVertScrlbar.pack(side ='right', fill ='y')
    listePhotos.configure(yscrollcommand = photVertScrlbar.set) 
     
    for item in enumerate(listePersos):
        addPersoListe=[item[1][0],item[1][1]]
        listePhotos.insert('',tk.END,values=addPersoListe)
     
    # Création du canvas
    cnAffPhoto= tk.Canvas(Onglet5, width= 300, height= 300)
    cnAffPhoto.place(x=40,y=40)
     
    FenetreBC_root.mainloop()
    Mais le plus surprenant, j'ai essayé de mettre un bout de code pour faire un update ou une manip pour voir mes photos, je me suis planté (j'ai laissé le bout de code erroné lignes 18-19), et là l'erreur m'a été indiquée (rien que de très normal...), mais mes photos sont apparues... D'où ma question, comment l'expliquer et comment faire apparaître mes photos sans avoir à générer une erreur (que je pourrais sans doute intercepter, mais ça n'est guère élégant) ?
    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
    import tkinter as tk
    from tkinter import ttk
    from PIL import Image,ImageTk
     
    listePersos=[("Mickey","Mickey300.jpg"),("Donald","Donald300.jpg"),("Picsou","Picsou300.jpg")]
     
    def affichPhoto(actionRealisee):
        """
        """     
        # Récupération des données du perso sélectionné dans le TreeView
        itemSelectionne = listePhotos.focus()
        refPhoto = listePhotos.item(itemSelectionne, 'values')
        # Chemin et nom de l'image
        cheminImage=str(refPhoto[1])
        # Construction de l'image
        trPhotoAAff = ImageTk.PhotoImage(Image.open(cheminImage))
        cnAffPhoto.create_image(10,10,anchor=tk.NW,image=trPhotoAAff)
        if FenetreBC_root.cnAffPhoto.winfo_exists():
            FenetreBC_root.cnAffPhoto.focus_set()
     
    FenetreBC_root = tk.Tk()
    FenetreBC_root.geometry('1280x777')
    FenetreBC_root.title('Cabinet de Phoniatrie Bruno')
    FenetreGestion_Photo = ttk.Frame(FenetreBC_root)
    FenetreGestion_Photo.place(x = 0, y = 0, width = 1280, height = 877)
     
     
    # Construction Table à onglets
    OngletAffichageBase = ttk.Notebook(FenetreGestion_Photo)
    OngletAffichageBase.place(x = 50, y = 100, width = 800, height = 500)
    Onglet1 = ttk.Frame(OngletAffichageBase)
    Onglet1.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet1, text = "Etat-civil")
    Onglet2 = ttk.Frame(OngletAffichageBase)
    Onglet2.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet2, text = "Diagnostic et correspondants")
    Onglet3 = ttk.Frame(OngletAffichageBase)
    Onglet3.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet3, text = "Actes")
    Onglet4 = ttk.Frame(OngletAffichageBase)
    Onglet4.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet4, text = "Courriers")
    Onglet5 = ttk.Frame(OngletAffichageBase)
    Onglet5.place(x = 0, y = 0, width = 795, height = 495)
    OngletAffichageBase.add(Onglet5, text = "Photos")
     
    # Liste multicolonnes des photos
    colonnes = ('IdPerso','NomFichier')
    listePhotos=ttk.Treeview(Onglet5, columns=colonnes, show='')
    # Constitutions des colonnes, avec entêtes non affichées
    listePhotos.heading('#0', text='')
    listePhotos.heading('IdPerso', text='Identification du perso')
    listePhotos.heading('NomFichier', text="Nom du fichier")
    listePhotos.column('#0', minwidth=0,width=0, stretch=tk.NO)
    listePhotos.column('IdPerso', minwidth=0,width=130)
    listePhotos.column('NomFichier', minwidth=0,width=0, stretch=tk.NO)
    listePhotos.place(x = 440, y = 100, width = 210, height = 260)
    listePhotos.bind("<<TreeviewSelect>>", affichPhoto)
    # Rajout d'une barre de défilement vertical
    photVertScrlbar = ttk.Scrollbar(listePhotos,orient ="vertical",command = listePhotos.yview)
    photVertScrlbar.pack(side ='right', fill ='y')
    listePhotos.configure(yscrollcommand = photVertScrlbar.set) 
     
    for item in enumerate(listePersos):
        addPersoListe=[item[1][0],item[1][1]]
        listePhotos.insert('',tk.END,values=addPersoListe)
     
    # Création du canvas
    cnAffPhoto= tk.Canvas(Onglet5, width= 300, height= 300)
    cnAffPhoto.place(x=40,y=40)
     
    FenetreBC_root.mainloop()
    Merci d'avance pour vos lumières et explications !
    Bruno
    Images attachées Images attachées    

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

Discussions similaires

  1. [FLASH MX] Affichage d'images par loadMovie
    Par n_tony dans le forum Flash
    Réponses: 7
    Dernier message: 23/09/2004, 15h34
  2. XSL: pb d'affichage d'images
    Par enez dans le forum XSL/XSLT/XPATH
    Réponses: 10
    Dernier message: 12/09/2004, 14h17
  3. PB affichage d'image avec IE
    Par arturo dans le forum Modules
    Réponses: 6
    Dernier message: 25/09/2003, 17h28
  4. [VB6] Affichage d'image avec qlq contraintes
    Par youri dans le forum VB 6 et antérieur
    Réponses: 3
    Dernier message: 21/11/2002, 14h44

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