Answered step by step
Verified Expert Solution
Link Copied!

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=-1, col=-1,c="):
self.ID = id
self. ROW = row
self. COL = COL
self. COLOR =C
self.BUTTON_OBJ = None
Check if two buttons have been clicked and if they are a match""."
def check_match():
global buttons
clicked =[]
for b in buttons. values():
if b.BUTTON_OB]['relief']== "sunken":
clicked.append (b)
if len(clicked)2 :
if clicked [0].BUTTON_OBJ ['bg']== clicked[1].BUTTON_OBJ ['bg '] :
# It's a match
clicked [0]. BUTTON_OBJ. configure(fg='black', bg='black', relief='raised')
clicked [1].BUTTON_OBJ. configure(fg='black', bg='black', relief='raised ')
# black
else:
clicked [0]. BUTTON_OBJ. configure (fg='SystemButtonFace', bg='SystemButtonFace', relief='raised ')
clicked [1].BUTTON_OB]. configure (fg='SystemButtonFace', bg='SystemButtonFace', relief=' raised')
If a button is pushed, draw the correct colors"'."
def button_pushed(pushed_id):
global buttons
buttons [pushed_id].BUTTON_OBJ.configure(bg=buttons[pushed_id].COLOR, 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 [pushed_id].BUTTON_OBJ.after(1500, check_match)
def close_options(top):
top.destroy()H
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions

Question

6. Identify seven types of hidden histories.

Answered: 1 week ago

Question

What is human nature?

Answered: 1 week ago