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 :

Pourquoi mon image ne s'affiche plus ?


Sujet :

Tkinter Python

  1. #1
    Membre à l'essai
    Homme Profil pro
    Etudiant
    Inscrit en
    Juin 2018
    Messages
    14
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Activité : Etudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juin 2018
    Messages : 14
    Points : 10
    Points
    10
    Par défaut Pourquoi mon image ne s'affiche plus ?
    J'avais une image qui fonctionnait avant, je n'ai pas changé de nom, ni déplacé le fichier. J'ai crée un Toplevel de ma classe contenant l'image et depuis elle ne s'affiche plus...
    De plus, essayer de lancer ce programme, l'affichage est extrêmement étrange lors de la génération, es-ce normal ?

    Code entier
    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
    # coding: utf-8
    from tkinter import *
    import tkinter as tk
    from tkinter.messagebox import *
     
    def toplevel():
     
        taille_x = int(E1.get()) #on reprend les valeurs précedentes 
        taille_y = int(E2.get())
        main = Toplevel(begin)
        main.title('CasioMaker by Tituya')
        main['bg'] = '#abc'
        nomfichier = 'DESSIN.txt'
        main.resizable(width=False,height=False)
     
     
        #A propos de l'affichage
        disp_x = 15
        disp_y = 15
     
        #reset du fichier
        fichier = open(nomfichier, 'w')
        fichier.write('\'Made by TituyaÙ\n')
        fichier.write('ClsÙ\n')
        fichier.write('ViewWindow 1,127,1,1,63,1Ù\n')
        fichier.write('AxesOffÙ\n')
        fichier.close()
     
        def a(): 
            #Ecriture dans le fichier
            fichier = open(nomfichier, 'w')
            fichier.write('\'Made by TituyaÙ\n')
            fichier.write('ClsÙ\n')
            fichier.write('ViewWindow 1,127,1,1,63,1Ù\n')
            fichier.write('AxesOffÙ\n')
            fichier.close()
     
        def c(): #Reset de la grille
            canvas.delete("all")
            for ligne1 in range(taille_y):
                for colonne1 in range(taille_x):
                    button = tk.Button(frame_b, borderwidth=1, background='white', width=2, height=1)
                    button['command'] = lambda button=button: button.configure(background = 'black')
                    button.grid(row=ligne1, column=colonne1)
                    fichier = open(nomfichier, 'w')
                    fichier.write('\'Made by TituyaÙ\n')
                    fichier.write('ClsÙ\n')
                    fichier.write('ViewWindow 1,127,1,1,63,1Ù\n')
                    fichier.write('AxesOffÙ\n')            
                    fichier.close()
     
        def b(): #Lors du quit
            if askyesno('Titre 1', 'Etes vous sur ? Toutes progression sera effacée'):
                main.destroy()
                begin.destroy()
            else:   
                pass
     
        def mouse(event):
            grid_info = event.widget.grid_info()
            if isinstance(event.widget, tk.Button):
                print("Ligne:", grid_info["row"] - 62, "Colonne:", grid_info["column"] + 1)
                point = canvas.create_line(grid_info["column"] + 2, grid_info["row"] + 2, grid_info["column"] + 2, grid_info["row"] + 3)
                fichier = open(nomfichier, 'a')
                value = (grid_info["column"] + 1)
                value2 = (grid_info["row"] - 63)
                valeur_colonne = str(value)
                valeur_ligne = str(-value2)
                fichier.write('PlotOn ' + valeur_colonne + ',' + valeur_ligne + \n')
     
        def tuto():
            root = Tk()
            root.title('Tutoriel')
            root['bg'] = '#abc'
            root.resizable(width=False,height=False)
            Label(root, text='Après avoir éffectué votre oeuvre,\n un fichier texte est crée où vous avez ouvert ce logiciel.\n Dans ce fichier, ce trouve les instructions pour la calculatrice.\n Ouvrez FA124 (logiciel de calculatrice).\n Connectez votre calculatrice puis, dans un nouveau programme,\n Copier puis Coller l\'ensemble du fichier texte dans un nouveau programme.\n Après ceci, tranférez le.\n Bravo, vous avez fini !', bg = '#abc').pack()
            root.mainloop()
     
     
        #Image CasioMaker
        photo = PhotoImage(file="casio_maker.png")
        frametxt = Frame(main, relief=FLAT)
        frametxt.pack(side=TOP)
        cantxt = Canvas(frametxt, width=300, height=25, bg=main['bg'], relief=FLAT)
        cantxt.create_image(150, 12, anchor=CENTER, image=photo)
        cantxt.pack(side=TOP)
     
        frame = Frame(main)
        frame.pack(padx=10, pady=100)
        can = Canvas(frame, background='yellow')
        can.grid(row=0, column=0)
     
        #Barre vertical
        vsbar = Scrollbar(frame, orient=VERTICAL, command=can.yview)
        vsbar.grid(row=0, column=1, sticky=NS)
        can.configure(yscrollcommand=vsbar.set)
        #Barre horizontal
        hsbar = Scrollbar(frame, orient=HORIZONTAL, command=can.xview)
        hsbar.grid(row=1, column=0, sticky=EW)
        can.configure(xscrollcommand=hsbar.set)
     
        frame_b = Frame(can)
     
        #Generation des boutons
        for ligne in range(taille_y):
            for colonne in range(taille_x):
                button = tk.Button(frame_b, borderwidth=1, background='white', width=2, height=1)
                button['command'] = lambda button=button: button.configure(background = 'black')
                button.grid(row=ligne, column=colonne)
     
                can.create_window((0,0), window=frame_b, anchor=NW)
                frame_b.update_idletasks()
                bbox = can.bbox(ALL)
     
                w, h = bbox[2]-bbox[1], bbox[3]-bbox[1]
                dw, dh = int((w/taille_x) * disp_x), int((h/taille_y) * disp_y)
                can.configure(scrollregion=bbox, width=dw, height=dh)
     
        #Menu du haut
        menu = Menu(main)
        sousmenu = Menu(menu, tearoff=0)
        menu.add_cascade(label="Menu", menu=sousmenu)
        sousmenu.add_command(label="Creer le fichier texte", command=a)
        sousmenu.add_command(label="Quitter", command=b)
        menu.add_command(label="Effacer", command=c)
        menu.add_command(label='Tutoriel', command=tuto)
        main.config(menu = menu)
     
        #Faux ecran de calc
        bottom_frame = Frame(main)
        bottom_frame.pack( side = BOTTOM )
     
        canvas = Canvas(bottom_frame, width=127, height=63, background='#7E9658')
        canvas.pack( side = BOTTOM)
     
        main.bind("<Button-1>", mouse)
     
    begin = Tk()
     
    x = StringVar(begin)
    y = StringVar(begin)
    x.set("10") #Valeur de base
    y.set("10") #Valeur de base
    E1=Entry(textvariable=x, width=7,justify=CENTER) #Entry 1 gérant x
    E2=Entry(textvariable=y, width=7,justify=CENTER) #Entry 2 gérant y
    E1.pack(side = RIGHT)
    E2.pack(side = RIGHT)
    go=Button(begin, text="lancer", command=toplevel) #bouton permettant le lancement de l'app
    go.pack()
     
    begin.mainloop()
    Extrait du code pour l'image
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    def toplevel():
     
        taille_x = int(E1.get()) #on reprend les valeurs précedentes 
        taille_y = int(E2.get())
        main = Toplevel(begin)
     
    #Image CasioMaker
        photo = PhotoImage(file="casio_maker.png")
        frametxt = Frame(main, relief=FLAT)
        frametxt.pack(side=TOP)
        cantxt = Canvas(frametxt, width=300, height=25, bg=main['bg'], relief=FLAT)
        cantxt.create_image(150, 12, anchor=CENTER, image=photo)
        cantxt.pack(side=TOP)
    Merci.

  2. #2
    Futur Membre du Club Avatar de NAIGRE1
    Homme Profil pro
    Collégien
    Inscrit en
    Juin 2018
    Messages
    12
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 17
    Localisation : Caraïbes

    Informations professionnelles :
    Activité : Collégien

    Informations forums :
    Inscription : Juin 2018
    Messages : 12
    Points : 7
    Points
    7
    Par défaut
    Je pense que ce code devrait sufir :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    def toplevel():
        global photo
        taille_x = int(E1.get()) #on reprend les valeurs précedentes 
        taille_y = int(E2.get())
        main = Toplevel(begin)
     
    #Image CasioMaker
        photo = PhotoImage(file="casio_maker.png")
        frametxt = Frame(main, relief=FLAT)
        frametxt.pack(side=TOP)
        cantxt = Canvas(frametxt, width=300, height=25, bg=main['bg'], relief=FLAT)
        cantxt.create_image(150, 12, anchor=CENTER, image=photo)
        cantxt.pack(side=TOP)
    Sinon c'est peut être une erreur de type d'image ; mais je ne pense pas car il n'y a pas de message d'erreur (enfin je crois )

    Mais pour pouvoir réutiliser des variable locales tel que " cantx " ou " frametxt " il vaudrait mieux globaliser plus de chose :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    def toplevel():
        global photo, cantxt, frametxt
        taille_x = int(E1.get()) #on reprend les valeurs précedentes 
        taille_y = int(E2.get())
        main = Toplevel(begin)
     
    #Image CasioMaker
        photo = PhotoImage(file="casio_maker.png")
        frametxt = Frame(main, relief=FLAT)
        frametxt.pack(side=TOP)
        cantxt = Canvas(frametxt, width=300, height=25, bg=main['bg'], relief=FLAT)
        cantxt.create_image(150, 12, anchor=CENTER, image=photo)
        cantxt.pack(side=TOP)

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

Discussions similaires

  1. pourquoi mon image ne s'affiche pas sur IE
    Par Ercan67000 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 22/06/2011, 12h31
  2. pourquoi mon image ne s'affiche pas
    Par zalalus dans le forum Windows Presentation Foundation
    Réponses: 7
    Dernier message: 20/05/2011, 11h42
  3. Pourquoi mon image ne s'affiche plus
    Par Gouyon dans le forum 2D
    Réponses: 5
    Dernier message: 18/03/2011, 13h51
  4. Les images ne s'affiche plus dans Mozilla Firefox
    Par sondo dans le forum Windows XP
    Réponses: 17
    Dernier message: 19/11/2008, 22h46
  5. mon image ne s'affiche pas
    Par vinc_dev_fr dans le forum AWT/Swing
    Réponses: 2
    Dernier message: 19/05/2007, 21h08

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