import tkinter as tk
from PIL import Image,ImageTk
import random
win = tk.Tk()
win.title('Country game')
win.geometry('2800x2800')
countries = ['Australia.png','Brazil.png','China.png','Egypt.png','France.png','Germany.png',
'Italy.png','Spain.png','UK.png']
random.shuffle(countries)
for country in countries:
img = Image.open(country)
landmark = ImageTk.PhotoImage(img)
btn = tk.Button(win,image=landmark)
btn.image = landmark
for i in range(3):
for j in range(3):
btn.grid(row=i,column=j)
For this program, it does not show any error messages. However my aim is to place the nine images randomly on the tkinter window, but when I run this program only one image button did appear. Although I used two for loops to grid other eight ones do not appear. May I ask what is the best method to place nine images for 3 rows and 3 images per row?