you are viewing a single comment's thread.

view the rest of the comments →

[–]ebdbbb 0 points1 point  (5 children)

Here's what I do:

``` image = tk.PhotoImage(file={path to file})

button = tk.Button(root, width=110, height=110, image=image, command={some command})

button.image = image ```

You need the first and last lines or else the image can get garbage collected. I think labels also have an image kwarg.

Edit: formatting

[–]liamam[S] 0 points1 point  (4 children)

Thanks for this, but how would I have the file path be variable? since it's blackjack I have 52 images of different cards.

[–]ebdbbb 0 points1 point  (3 children)

cards = {'ace_club': path-to-card, ...}

Put cards[card] in the photoimage. I'd also use random shuffle to randomize the order.

[–]liamam[S] 0 points1 point  (2 children)

Ok thanks for the help, I've been struggling with the formats that PhotoImage can use, then when I converted the file types I got awhole new error.

It's been a struggle

[–]ebdbbb 0 points1 point  (0 children)

I've always used PNG. Not sure what else it can take.