#๐ Matching Game (in gui): 2nd card flipping back over instantly
110 messages ยท Page 1 of 1 (latest)
@barren echo
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
i think its something to do with show_card()
im talking about the if conditions
also this doesnt match what your pastebin has
can you tell me about your flipped logic
i think it should be in a loop
got it
it means i have flipped one card
ok so now there are 2 cards flipped
just use time?
time.sleep()
no in your check_match
you have use 1 second
increase it maybe?
what stops?
its because in your check_match method
you mention sleep before making it gray
wait no
Hey @barren echo!
It looks like you pasted Python code without syntax highlighting.
Please use syntax highlighting to improve the legibility of your code and make it easier for us to help you.
To do this, use the following method:
```py
print('Hello, world!')
```
This will result in the following:
print('Hello, world!')```
You can **edit your original message** to correct your code block.
just try it
dont forget to keep your old code
wait
where are you exactly calling the method show_card?
its in the load_card() let me see
yes
would you mind sharing your cs50 so i can try running the code myself
just copy paste the code
oh wait its a module
yep
this is the same code
oh i dont have cs50
imma just visually try finding whats wrong
im not that good at python
maybe we should wait for some expert
till then ill try
def show_card(row, col):
global first
global second
global flipped
buttons[row * 18 + col].config(text=board[row][col])
time.sleep(0.5)
flipped += 1
if flipped == 1:
first = (row, col)
if flipped == 2:
second = (row, col)
flipped = 0
time.sleep(1)
check_match()```
can you try this? @barren echo
so when you click on the first card, it shows properly?
now on clicking the second, can you tell me what happens? with your original code, not mine
showing the grey card?
i see
@barren echo what are you checking in the first condition and what in the second?
if first != second:
if board[frow][fcol] == board[srow][scol]:
mhm
and in the second?
why do you need 2 conditions
like you are using 2 if statements
this?
if first != second:
if board[frow][fcol] == board[srow][scol]:
i think either condition would get the job done, no?
are you sure you have indented the else block properly
im stumped
everything looks like its supposed to work
hold on im calling someone
nobody's listening ๐ญ
ive been trying for so long
i got you 2 people now
so its a card matching game and well, its not matching
lmao
Can I get the code for cs50?
I'm trying to run your code so I can try to debug it
But I cant because no cs50
Pastebin
do you have to install it separately?
Cuz right now I'm getting this:
line 1, in <module>
from cs50 import get_string, get_int, get_char
ModuleNotFoundError: No module named 'cs50'
cs50 gui or whatever it is
!pip cs50
how do i like install it
Its OK I got it
py -m pip install cs50
It looks like none of the cs50 functions are being used in this script
where do i run this exactly? im on macOS ๐
Are you supposed to?
In your terminal, type python3 -m pip install cs50
ok
@barren echo Are you supposed to use those functions from cs50? Like get_string, get_int, etc
oh damn
then its useless?
Are you taught to use globals in Python from CS50 or is that because someone suggested you to use globals? @barren echo
I think its fine for now. I'm able to "run" the code for now
can you give your latest code, the one i have shows multiple cards at once
Second card does show up but it quickly hides it if its incorrect
If it matches, its grayed out
whats the issue?
it does
it works when i choose 2 correct ones, but the second one still doesnt show
this would be much easier in pygame
pygame is python
idk tkinter but I would guess you measure frames
if you are running at 60fps, after 30 frames 0.5 seconds has passed
otherwise you find a way to import an animation
OP is using tkinter. There's no FPS here
it has a main loop
so yes it does
In this video I'll show you how to use timers with TKinter. We'll also build a cool digital clock.
There are many times when you need to run things on a timer with Tkinter. Wait x seconds before running this function, or opening that window, etc. How do you do it?
Most tkinter widgets have a built in function called .after() that acts as a ...
in the video it shows the guy defining a clock function which compares the current time to the start time to see the duration of time passed and that function is passed into the mainloop as a command
watch the video
it shows exactly how to do it
interesting
i dont use tkinter so idk but if it works then the issue is solved?
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.