Bonjour, je développe en ce moment un jeu éducatif ou l'utilisateur doit reproduire à l'identique une piece industriel par rapport à un model imposé par l'ordinateur. Je me tourne aujourd'hui vers la communauté car j'ai un problème au niveau de l'interface graphique. J'ai une classe Piece et une classe Application. Dans la classe Piece, il y a une méthode dessinePiece qui dessine la piece dans un canvas (attribut d'instance de l'objet Piece). Or je veux que ce canvas soit contenu dans la fenetre principale crée dans la classe Application. Et là, j'ai cette erreur :
Traceback (most recent call last):
File "/Users/boriselgareh/Downloads/DMV2 5/Application.py", line 31, in <module>
Application(8).mainloop()
File "/Users/boriselgareh/Downloads/DMV2 5/Application.py", line 11, in __init__
self.initFenetre()
File "/Users/boriselgareh/Downloads/DMV2 5/Application.py", line 16, in initFenetre
self.afficheChaine=VueChaine(self,self.nbCotes)
File "/Users/boriselgareh/Downloads/DMV2 5/VueChaine.py", line 11, in __init__
self.creerChaine()
File "/Users/boriselgareh/Downloads/DMV2 5/VueChaine.py", line 15, in creerChaine
self.machine = VueMachine(self,i)
File "/Users/boriselgareh/Downloads/DMV2 5/VueMachine.py", line 21, in __init__
self.can.create_image(0,0,image=self.photo,anchor="nw")
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2329, in create_image
return self._create('image', args, kw)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 2320, in _create
*(args + self._options(cnf, kw))))
_tkinter.TclError: image "pyimage1" doesn't exist
Voici mon code :
from random import *
from math import *
from tkinter import *
class Piece(object):
def __init__(self,can=Canvas(),x=100,y=100,r=100,nbCotes=8):
self.__nbCotes=nbCotes
self.__can=can
self.xCentre=x
self.yCentre=y
self.rayon=r
self.generer()
def dessinerPieces(self):
sommets=[]
for i in range(self.getNbCotes()):
sommets.append([self.xCentre+self.rayon * cos(2 * pi * (i+1/2) / self.getNbCotes()),
self.yCentre +self.rayon * sin(2 * pi * (i+1/2) / self.getNbCotes())])
self.getCan().create_polygon(sommets, outline='gray', fill='gray')
self.getCan().pack()
delta=self.rayon-self.rayon*cos(pi/self.getNbCotes())
angle = (2 * pi) / self.getNbCotes()
for i in range(self.getNbCotes()//2):
if self.traits[i] != 0:
x0 = self.xCentre + (self.rayon - delta) * cos(angle * i)
x1 = self.xCentre + (self.rayon - delta) * cos(angle * i + pi)
y0 = self.yCentre + (self.rayon - delta) * sin(angle * i)
y1 = self.yCentre + (self.rayon - delta) * sin(angle * i + pi)
self.getCan().create_line(x0, y0, x1, y1, width=self.traits[i]**2, fill='lightgrey')
if self.trous[i] == 2 or self.trous[i] == 3:
x0 = self.xCentre + (self.rayon - delta) / 1.25 * cos(angle * i) - 7
y0 = self.yCentre + (self.rayon - delta) / 1.25 * sin(angle * i) - 7
x1 = self.xCentre + (self.rayon - delta) / 1.25 * cos(angle * i) + 7
y1 = self.yCentre + (self.rayon - delta) / 1.25 * sin(angle * i) + 7
x2 = self.xCentre + (self.rayon - delta) / 1.25 * cos(angle * i + pi) - 7
y2 = self.yCentre + (self.rayon - delta) / 1.25 * sin(angle * i + pi) - 7
x3 = self.xCentre + (self.rayon - delta) / 1.25 * cos(angle * i + pi) + 7
y3 = self.yCentre + (self.rayon - delta) / 1.25 * sin(angle * i + pi) + 7
self.getCan().create_oval(x0, y0, x1, y1, fill='yellow')
self.getCan().create_oval(x2, y2, x3, y3, fill='yellow')
if 1 or 3 in self.traits :
x = self.xCentre
y = self.yCentre
self.getCan().create_oval(x - 7, y - 7, x + 7, y + 7, fill='yellow')
from VueChaine import * from Chaine import * from tkinter import * from Piece import *
class Application(Tk): def __init__(self,nbCotes): Tk.__init__(self) self.nbCotes=nbCotes self.initFenetre()
if __name__=="__main__": Application(8).mainloop()
J'espère que quelqu'un puisse me venir en aide! Merci
IG Tkinter," image "pyimage1" doesn't exist"
× Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
× Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.