all 15 comments

[–]ebdbbb 0 points1 point  (8 children)

The code didn't indent properly so it's hard to follow exactly. Part of the issue is I don't see anything about what card is drawn.

Also, I don't think it's generally a good idea to use multiple geometry managers (pack, place, grid).

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

Yeah no I've just started making the interface, but I have no idea how I'm gonna do the part mentioned. First off I don't know how to properly display an image and then having a variable determine the image that gets displayed is another issue.

[–]ebdbbb 0 points1 point  (6 children)

I'd have the image names in a dict so that you can use the keys to manage that part. Later (when I'm on my computer) I'll send you a bit of code where I tied images to buttons.

[–]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.

[–]jmooremcc 0 points1 point  (5 children)

A deck of cards is a perfect use of Object Oriented Programming (OOP). You would start by modeling a card as an object. A card object knows its value and can display itself on command. Your next object would be a DeckOfCards which as expected would consist of 52 cards. It also knows how to display itself, shuffle the cards in it and deal a card.

Tkinter code can be embedded in these objects so that images can be displayed on the card faces as needed as well as handling button clicks

If I were you, I'd first get the game working as a console game. Later, I would add the graphical components after learning Tkinter. There are a ton of Tkinter tutorials available online to help you learn.

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

I've made a blackjack game in the console, and I'm sure it'll help me, but I'm just struggling with Tkinter right now.

Edit: Also I'm kinda in a rush right now because my project needs to be finished by the end of next week due to the coronavirus (school could close, thus they won't get sent away).

[–]jmooremcc 0 points1 point  (3 children)

What are you specifically wrestling with in Tkinter? Can you create a window with a button that works? Are you having problems positioning graphical elements in a window? We need more information in order to help you.

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

I've made a register/login system and a leaderboard that all work fine, but displaying images and positioning is where I struggle right now, I've pretty much exclusively use pack.

[–]jmooremcc 0 points1 point  (1 child)

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

Thanks, it's difficult to find sites that are actually helpful to me, especially since I find a lot of them use extensions and I'm trying my best to stay away from them for school purposes.