Given the non OOP code of Tic Tac Toe below, make it a OOP approach. Use python as programming language. from tkinter import * root = Tk() root.title('Ysmael Trias - Tic Tac Toe') # To set the title of the application root.geometry('510x537') # To set the size of the window of the application player = 'X' stop_game = False def callback(r, c): global player if player == 'X' and states[r][c] == 0 and stop_game==False: b[r][c].configure(text='X', fg='yellow', bg='blue') states[r][c] = 'X' player = 'O' if player == 'O' and states[r][c] == 0 and stop_game==False: b[r][c].configure(text='O', fg='green', bg='red') states[r][c] = 'O' player = 'X' check_for_winner() def check_for_winner(): global stop_game for i in range(3): if states[i][0]==states[i][1]==states[i][2]!=0: b[i][0].configure(bg='black') b[i][1].configure(bg='black') b[i][2].configure(bg='black') stop_game = True for i in range(3): if states[0][i]==states[1][i]==states[2][i]!=0: b[0][0].configure(bg='black') b[1][i].configure(bg='black') b[2][i].configure(bg='black') stop_game = True if states[0][0]==states[1][1]==states[2][2]!=0: b[0][0].configure(bg='black') b[1][1].configure(bg='black') b[2][2].configure(bg='black') stop_game = True if states[2][0]==states[1][1]==states[0][2]!=0: b[2][0].configure(bg='black') b[1][1].configure(bg='black') b[0][2].configure(bg='black') stop_game = True b = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] states = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] def reset(): global stop_game for i in range(3): for j in range(3): b[i][j].configure(text='', fg='black', bg='powder blue') states[i][j] = 0 stop_game = False for i in range(3): for j in range(3): b[i][j] = Button(font=('Calibri', 58, 'bold'), width=4, bg='powder blue', command=lambda r=i, c=j: callback(r, c)) b[i][j].grid(row=i, column=j) reset_game = Button(text='Reset', font=('Calibri', 15, 'bold'), width=4, height=1, fg='black', bg='green', command=lambda :reset()) reset_game.grid(row=3, column=0, columnspan=2, sticky='nsew') exit_game = Button(text='Exit', font=('Calibri', 15, 'bold'), width=4, height=1, fg='black', bg='green', command=lambda :root.destroy()) exit_game.grid(row=3, column=2, columnspan=2, sticky='nsew') root.resizable(0, 0) mainloop()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
Given the non OOP code of Tic Tac Toe below, make it a OOP approach. Use python as programming language. from tkinter import * root = Tk() root.title('Ysmael Trias - Tic Tac Toe') # To set the title of the application root.geometry('510x537') # To set the size of the window of the application player = 'X' stop_game = False def callback(r, c): global player if player == 'X' and states[r][c] == 0 and stop_game==False: b[r][c].configure(text='X', fg='yellow', bg='blue') states[r][c] = 'X' player = 'O' if player == 'O' and states[r][c] == 0 and stop_game==False: b[r][c].configure(text='O', fg='green', bg='red') states[r][c] = 'O' player = 'X' check_for_winner() def check_for_winner(): global stop_game for i in range(3): if states[i][0]==states[i][1]==states[i][2]!=0: b[i][0].configure(bg='black') b[i][1].configure(bg='black') b[i][2].configure(bg='black') stop_game = True for i in range(3): if states[0][i]==states[1][i]==states[2][i]!=0: b[0][0].configure(bg='black') b[1][i].configure(bg='black') b[2][i].configure(bg='black') stop_game = True if states[0][0]==states[1][1]==states[2][2]!=0: b[0][0].configure(bg='black') b[1][1].configure(bg='black') b[2][2].configure(bg='black') stop_game = True if states[2][0]==states[1][1]==states[0][2]!=0: b[2][0].configure(bg='black') b[1][1].configure(bg='black') b[0][2].configure(bg='black') stop_game = True b = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] states = [[0, 0, 0], [0, 0, 0], [0, 0, 0]] def reset(): global stop_game for i in range(3): for j in range(3): b[i][j].configure(text='', fg='black', bg='powder blue') states[i][j] = 0 stop_game = False for i in range(3): for j in range(3): b[i][j] = Button(font=('Calibri', 58, 'bold'), width=4, bg='powder blue', command=lambda r=i, c=j: callback(r, c)) b[i][j].grid(row=i, column=j) reset_game = Button(text='Reset', font=('Calibri', 15, 'bold'), width=4, height=1, fg='black', bg='green', command=lambda :reset()) reset_game.grid(row=3, column=0, columnspan=2, sticky='nsew') exit_game = Button(text='Exit', font=('Calibri', 15, 'bold'), width=4, height=1, fg='black', bg='green', command=lambda :root.destroy()) exit_game.grid(row=3, column=2, columnspan=2, sticky='nsew') root.resizable(0, 0) mainloop()
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education