Place image on canvas from a list with tkinter
Farx69
Posted messages
4
Status
Member
-
Farx69 -
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
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
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
-
yg_be Posted messages 23437 Registration date Status Contributor Last intervention Ambassadeur 1 588
Hello,
I don’t really understand what you did before.-
#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 -
-
-
-
-