Place image on canvas from a list with tkinter

Farx69 Posted messages 4 Status Member -  
 Farx69 -
En gros, à partir d'une liste je dois créer un plateau, en gros chaque lettre dans la liste correspond à un emplacement sur la plateau et a une image spécifique, le soucis c'est que je comprends pas comment faire ça donc pour l'instant, j'ai fait ça mais je comprends pas trop ce que je dois faire après
 T = PhotoImage(file="brique.jpg") P = PhotoImage(file="fromage.jpg") H = PhotoImage(file="echelle.png") for i in range(len(plateau)): for j in range(len(plateau[i])): n = j if l == "T": l==T elif l =="P": l==P elif l=="H": l==H 

comme exemple j'ai ça, mais ça doit marcher avec n'importe quel fichier texte :


Merci d'avance pour toute aide

Configuration: Windows / Chrome 100.0.4896.127

1 answer

  1. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   Ambassadeur 1 588
     
    Hello,
    I don’t really understand what you did before.
    0
    1. Farx69 Posted messages 4 Status Member
       
      #Instruction 1 fen = Tk() fen.title('Cat and Mouse Game') fen.geometry('1200x680') fen.iconbitmap("jerry.ico") ch2 = IntVar() button1=Radiobutton(fen,text="Board 1",variable=ch2,value=0).place(x="0",y="0") button2=Radiobutton(fen,text="Board 2",variable=ch2,value=1).place(x="0",y="20") button3=Radiobutton(fen,text="Board 3",variable=ch2,value=2).place(x="0",y="40") button4=Radiobutton(fen,text="Board 4",variable=ch2,value=3).place(x="0",y="60") button5=Radiobutton(fen,text="Board 5",variable=ch2,value=4).place(x="0",y="80") can1 = Canvas(fen,bg='white',height='1200',width='680') can1.pack() #Instruction 2 #File loaded into a two-dimensional list, and instead of niv0.txt, we put the desired level file. plateau= [] #file opening with open('niv0.txt') as f: # we go through all lines of the file for ligne in f: #a list that will serve to save each letter of the line in the file ligne_plateau = [] #for each letter in the line of the file for lettre in ligne: #we do not record line breaks if lettre != "\n": #we add it to our list ligne_plateau.append(lettre) #we save the list in the plateau plateau.append(ligne_plateau) print(plateau) T = PhotoImage(file="brick.jpg") P = PhotoImage(file="cheese.jpg") H = PhotoImage(file="amp.png") X = PhotoImage(file="steel.jpg") for i in range(len(plateau)): for j in range(len(plateau[i])): n = j if n == "T": n==T elif n =="P": n==P elif n=="H": n==H elif n=="X": n==X
      0
    2. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > Farx69 Posted messages 4 Status Member
       
      What should you do next?
      Is this your first exercise with tkinter?
      What are you trying to do on line 45?
      0
    3. Farx69 Posted messages 4 Status Member > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
       
      It's for classes and yes, basically I have to go through the list, and in the list each letter corresponds to an image. The problem is that I don't know how to create an image with tkinter and how to place it, and on line 45 I made a mistake, I deleted it.
      0
    4. yg_be Posted messages 23437 Registration date   Status Contributor Last intervention   1 588 > Farx69 Posted messages 4 Status Member
       
      If you don't know how to make an image with tkinter, I suggest you start with a simpler exercise:
      "make an image with tkinter".

      How did you get to a complex exercise without doing the simple exercises first?
      0
    5. Farx69 Posted messages 4 Status Member > yg_be Posted messages 23437 Registration date   Status Contributor Last intervention  
       
      That's a homework assignment in Computer Science, I have to turn it in tomorrow, that's why I'm getting busy.
      0