# download modules
import random
import tkinter as tk
from PIL import ImageTk, Image

# main-class


class DiceSimu(tk.Tk):
    def __init__(self, className) -> None:
        super().__init__(className=className)
        self.title('Dice Simulator')
        self.resizable(0, 0)
        self.geometry('600x350')

        # how to add a icon for the program
        self.p1 = tk.PhotoImage(file='./dices_imgs/dice.png')
        self.iconphoto(False, self.p1)

        self.welcome_lbl = tk.Label(self, text='Welcomme to the Dice Simulator',
                                    fg='blue',
                                    bg='yellow')
        self.welcome_lbl.pack(pady=30)
        
        self.dice_list = ['dice_one.png', 'dice_two.png', 'dice_three.png',
                          'dice_four.png', 'dice_five.png', 'dice_six.png']
        #label for image
        self.my_label = tk.Label(image=self.get_image(re_turn=True), height=200, width=300)
        self.my_label.pack()
        #button for rolling
        self.roll_btn = tk.Button(self, text='Roll the Dice', command=self.get_image)
        self.roll_btn.pack(pady=25)

    def get_image(self, re_turn=False):
        # how to open an image and resized it.
        picture = random.choice(self.dice_list)
        img = Image.open(f'./dices_imgs/{picture}')
        my_img = ImageTk.PhotoImage(img.resize((300, 205), Image.ANTIALIAS))

        if re_turn:
            return my_img
        else:
            self.my_label.config(image=my_img)
            # this is for garbage collaction
            self.my_label.image = my_img


if __name__ == '__main__':
    dice_simu = DiceSimu(className='Dice Simulator')
    dice_simu.mainloop()

# download modules
import random
import tkinter as tk
from PIL import ImageTk, Image

# main-class


class DiceSimu(tk.Tk):
    def __init__(self, className) -> None:
        super().__init__(className=className)
        self.title('Dice Simulator')
        self.resizable(0, 0)
        self.geometry('600x350')

        # how to add a icon for the program
        self.p1 = tk.PhotoImage(file='./dices_imgs/dice.png')
        self.iconphoto(False, self.p1)

        self.welcome_lbl = tk.Label(self, text='Welcomme to the Dice Simulator',
                                    fg='blue',
                                    bg='yellow')
        self.welcome_lbl.pack(pady=30)
        
        self.dice_list = ['dice_one.png', 'dice_two.png', 'dice_three.png',
                          'dice_four.png', 'dice_five.png', 'dice_six.png']
        #label for image
        self.my_label = tk.Label(image=self.get_image(re_turn=True), height=200, width=300)
        self.my_label.pack()
        #button for rolling
        self.roll_btn = tk.Button(self, text='Roll the Dice', command=self.get_image)
        self.roll_btn.pack(pady=25)

    def get_image(self, re_turn=False):
        # how to open an image and resized it.
        picture = random.choice(self.dice_list)
        img = Image.open(f'./dices_imgs/{picture}')
        my_img = ImageTk.PhotoImage(img.resize((300, 205), Image.ANTIALIAS))

        if re_turn:
            return my_img
        else:
            self.my_label.config(image=my_img)
            # this is for garbage collaction
            self.my_label.image = my_img


if __name__ == '__main__':
    dice_simu = DiceSimu(className='Dice Simulator')
    dice_simu.mainloop()

# download modules # main-class # how to add a icon for the program #label for image #button for rolling # how to open an image and resized it. # this is for garbage collaction