vendredi 21 janvier 2022

How do I show random images from a folder on Tkinter?

So I have a couple of images in a folder and I want to do a little pack opener on tkinter where if I press on a button it randomly opens an Image of that folder and shows it. So I did this:

def pack():
    path ='C:\\Users\\matt\OneDrive\Images\cards'
    files = os.listdir(path)
    index = random.randrange(0, len(files))
    image = Image.open(files[index])
    image.show()

The problem is that this function doesn't want to work and it always tells me:

AttributeError: type object 'Image' has no attribute 'open'

Can someone please help me? And does someone know how to do a button out of an image? Thank you in advance.☺




Aucun commentaire:

Enregistrer un commentaire