May-03-2021, 08:21 PM
Images in buttons is pretty easy. Just create an image for the flag, then when you flag a cell set the text to '' and set the image. I clipped this from a tk Yahtzee game.
import pathlib import tkinter as tk import random IMAGE_DIR = pathlib.Path(__file__).parent class DiceButton(tk.Button): """Roll a die""" def __init__(self, parent): # Create dice images self.images = [tk.PhotoImage(file=IMAGE_DIR/f'dice{i}.png') for i in range(7)] super().__init__(parent, image=self.images[0], command=self.roll) self.value = 0 def roll(self): self.value = random.randint(1, 6) self['image'] = self.images[self.value] ROOT = tk.Tk() for _ in range(6): DiceButton(ROOT).pack(side=tk.LEFT) ROOT.mainloop()