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 :

comment afficher plusieurs images avec tkinter


Sujet :

Tkinter Python

  1. #1
    Candidat au Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Avril 2017
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2017
    Messages : 1
    Points : 2
    Points
    2
    Par défaut comment afficher plusieurs images avec tkinter
    Bonjour à tous, voilà une amie et moi devons faire un programme scientifique. Mais nous avons un énorme problème malgré de nombreuses recherches. On veut créer un jeu sur les 20 acides aminées en mettant plusieurs images de ces acides et en insérant juste à côté un choix multiple ( un genre de check liste) qui en cliquant dessus nous montrera si la réponse correspond à la photo ( système de vérification).
    Nous avons fait ce code en tkinter sur python 3 ( ci dessous) qui je vous l'accorde est déjà trop long mais surtout les images ne s'appliquent pas , le programme montre juste des cases de couleur.. Pouvez vous, nous aider à raccourcir ce code et surtout nous permettre de mettre plusieurs images? *Merci *
    *
    voici le code :

    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
    from tkinter import * 
     
    fen1 = Tk() 
     
    # création d'un widget 'Canvas' contenant une image bitmap : 
    can1 = Canvas(fen1, width =160, height =160, bg ='white') 
    photo = PhotoImage(file ='ala.gif') 
    item = can1.create_image(80, 80, image =photo) 
    can2 = Canvas(fen1, width =160, height =160, bg ='black') 
    photo = PhotoImage(file ='leu.gif') 
    item = can2.create_image(100, 100, image =photo) 
    can3 = Canvas(fen1, width =160, height =160, bg ='blue') 
    photo = PhotoImage(file ='gly.gif') 
    item = can3.create_image(200, 200, image =photo) 
    can4 = Canvas(fen1, width =160, height =160, bg ='green') 
    photo = PhotoImage(file ='gly.gif') 
    item = can4.create_image(200, 200, image =photo) 
    can5 = Canvas(fen1, width =160, height =160, bg ='gold') 
    photo = PhotoImage(file ='gly.gif') 
    item = can5.create_image(200, 200, image =photo) 
    can6 = Canvas(fen1, width =160, height =160, bg ='magenta') 
    photo = PhotoImage(file ='gly.gif') 
    item = can6.create_image(200, 200, image =photo) 
    can7 = Canvas(fen1, width =160, height =160, bg ='#234567') 
    photo = PhotoImage(file ='gly.gif') 
    item = can7.create_image(200, 200, image =photo) 
    can8 = Canvas(fen1, width =160, height =160, bg ='#098765') 
    photo = PhotoImage(file ='gly.gif') 
    item = can8.create_image(200, 200, image =photo) 
    can9 = Canvas(fen1, width =160, height =160, bg ='#453627') 
    photo = PhotoImage(file ='gly.gif') 
    item = can9.create_image(200, 200, image =photo) 
    can10 = Canvas(fen1, width =160, height =160, bg ='#102938') 
    photo = PhotoImage(file ='gly.gif') 
    item = can10.create_image(200, 200, image =photo) 
    can11 = Canvas(fen1, width =160, height =160, bg ='#928374') 
    photo = PhotoImage(file ='gly.gif') 
    item = can11.create_image(200, 200, image =photo) 
    can12 = Canvas(fen1, width =160, height =160, bg ='#610384') 
    photo = PhotoImage(file ='gly.gif') 
    item = can12.create_image(200, 200, image =photo) 
    can13 = Canvas(fen1, width =160, height =160, bg ='#777777') 
    photo = PhotoImage(file ='gly.gif') 
    item = can13.create_image(200, 200, image =photo) 
    can14 = Canvas(fen1, width =160, height =160, bg ='#001234') 
    photo = PhotoImage(file ='gly.gif') 
    item = can14.create_image(200, 200, image =photo) 
    can15 = Canvas(fen1, width =160, height =160, bg ='#619247') 
    photo = PhotoImage(file ='gly.gif') 
    item = can15.create_image(200, 200, image =photo) 
    can16 = Canvas(fen1, width =160, height =160, bg ='#716354') 
    photo = PhotoImage(file ='gly.gif') 
    item = can16.create_image(200, 200, image =photo) 
    can17 = Canvas(fen1, width =160, height =160, bg ='#840294') 
    photo = PhotoImage(file ='gly.gif') 
    item = can17.create_image(200, 200, image =photo) 
    can18 = Canvas(fen1, width =160, height =160, bg ='#386334') 
    photo = PhotoImage(file ='gly.gif') 
    item = can18.create_image(200, 200, image =photo) 
    can19 = Canvas(fen1, width =160, height =160, bg ='#046384') 
    photo = PhotoImage(file ='gly.gif') 
    item = can19.create_image(200, 200, image =photo) 
    can20 = Canvas(fen1, width =160, height =160, bg ='#105384') 
    photo = PhotoImage(file ='gly.gif') 
    item = can20.create_image(200, 200, image =photo) 
    # Mise en page à l'aide de la méthode 'grid' : 
    can1.grid(row =1, column =1, rowspan =3, padx =[0,100], pady =5) 
    can2.grid(row =10, column =1, rowspan =3, padx =[0,100], pady =5) 
    can3.grid(row =20, column =1, rowspan =3, padx =[0,100], pady =5) 
    can4.grid(row =30, column =1, rowspan =3, padx =[0,100], pady =5) 
    can5.grid(row =40, column =1, rowspan =3, padx =[0,100], pady =5) 
    can6.grid(row =1, column =2, rowspan =3, padx =[100,200], pady =5) 
    can7.grid(row =10, column =2, rowspan =3, padx =[100,200], pady =5) 
    can8.grid(row =20, column =2, rowspan =3, padx =[100,200], pady =5) 
    can9.grid(row =30, column =2, rowspan =3, padx =[100,200], pady =5) 
    can10.grid(row =40, column =2, rowspan =3, padx =[100,200], pady =5) 
    can11.grid(row =1, column =3, rowspan =3, padx =[0,200], pady =5) 
    can12.grid(row =10, column =3, rowspan =3, padx =[0,200], pady =5) 
    can13.grid(row =20, column =3, rowspan =3, padx =[0,200], pady =5) 
    can14.grid(row =30, column =3, rowspan =3, padx =[0,200], pady =5) 
    can15.grid(row =40, column =3, rowspan =3, padx =[0,200], pady =5) 
    can16.grid(row =1, column =4, rowspan =3, padx =[0,200], pady =5) 
    can17.grid(row =10, column =4, rowspan =3, padx =[0,200], pady =5) 
    can18.grid(row =20, column =4, rowspan =3, padx =[0,200], pady =5) 
    can19.grid(row =30, column =4, rowspan =3, padx =[0,200], pady =5) 
    can20.grid(row =40, column =4, rowspan =3, padx =[0,200], pady =5) 
     
    # démarrage : 
    fen1.mainloop()

  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 Carotiziana Voir le message
    le programme montre juste des cases de couleur.. Pouvez vous, nous aider à raccourcir ce code et surtout nous permettre de mettre plusieurs images? *Merci *
    Côté image, c'est la même question/code/erreur que dans cette discussion... Allez y lire la réponse.

    Pour raccourcir le code, il faut apprendre les type de base que sont listes, dictionnaires,... et les constructions (boucles) qui vont avec.... Et les tutos sont là pour vous permettre d'apprendre à les utiliser.

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

Discussions similaires

  1. [Débutant] comment afficher plusieurs images dans une seule interface ?
    Par youssa81 dans le forum Interfaces Graphiques
    Réponses: 3
    Dernier message: 06/02/2009, 00h36
  2. Comment afficher plusieurs images depuis une BD en même temps ?
    Par thibouille dans le forum Bases de données
    Réponses: 2
    Dernier message: 06/11/2007, 15h36
  3. Comment afficher les images avec firefox ?
    Par 12monkeys dans le forum Balisage (X)HTML et validation W3C
    Réponses: 3
    Dernier message: 23/11/2006, 20h59
  4. Réponses: 6
    Dernier message: 19/05/2006, 14h22
  5. PL/SQL - Comment afficher une image avec HTP ?
    Par patmaba dans le forum PL/SQL
    Réponses: 2
    Dernier message: 08/07/2004, 09h28

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