Answered step by step
Verified Expert Solution
Question
1 Approved Answer
import time from tkinter import * from random import randint class ButtonWrapper: def ( self , id = ' , row = -
import time
from tkinter import
from random import randint
class ButtonWrapper:
def self id row col:
self.ID id
self. ROW row
self. COL COL
self. COLOR
self.BUTTONOBJ None
Check if two buttons have been clicked and if they are a match""."
def checkmatch:
global buttons
clicked
for in buttons. values:
if bBUTTONOBrelief "sunken":
clicked.append b
if lenclicked :
if clicked BUTTONOBJ bg clickedBUTTONOBJ bg :
# It's a match
clicked BUTTONOBJ. configurefg'black', bg'black', relief'raised'
clicked BUTTONOBJ. configurefg'black', bg'black', relief'raised
# black
else:
clicked BUTTONOBJ. configure fg'SystemButtonFace', bg'SystemButtonFace', relief'raised
clicked BUTTONOB configure fg'SystemButtonFace', bg'SystemButtonFace', relief raised'
If a button is pushed, draw the correct colors"
def buttonpushedpushedid:
global buttons
buttons pushedidBUTTONOBJ.configurebgbuttonspushedidCOLOR, relief"sunken"
# Because time.sleep blocks execution, the color change for the second button clicked does not take effect until
# the function returns. So we need to use the 'after method
# Parameters:
# parent: is the object of the widget or main window whichever is using this function.
# ms: is the time in milliseconds.
# function: which shall be called.
# args: other options.
buttons pushedidBUTTONOBJ.after checkmatch
def closeoptionstop:
top.destroyH
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started