Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

USE!!!PYTHON!!!! The goal of this assignment is to use tkinter to produce a clas

ID: 3665276 • Letter: U

Question

USE!!!PYTHON!!!!

The goal of this assignment is to use tkinter to produce a class hangman that allows the user to play a simple game of hangman.   It will loosely follow the strategy we used for the calculator in class. Follow these guidelines:

1. Write a (module level, not in the class) function mask that takes two string arguments, the first a word the second containing exceptions.   The function mask returns a string in which every character in the word has been replaced by ‘?’ except for the characters in exceptions. For example:

>>> mask('APPLE','AE')

'A???E'

>>> mask('APPLE','')

'?????'

>>>mask('APPLE','PLEASE')

'APPLE'

>>>

2. The interface:

a. hangman should inherit from Frame.

b. Hangman Label & Entry displays the current state of the word

c. Right Label & Entry – letters guessed correctly so far (no repeats listed)

d. Wrong Label & Entry – letters guessed incorrectly so far (repeats not listed)

e. 26 buttons, one for each letter of the alphabet

3. Gameplay. The player clicks on a letter button. Three things can happen:

a. the letter is already in either the list of right or wrong letters.In this case nothing happens.

b. the letter is in the word (but not in either list).Then that letter is added to the list of right letters, the word is remasked and the masked word (use mask) is displayed next to Hangman (in effect revealing the new letter).   If the word is finished a showinfo box states “You Win!”

c. the letter is not in the word (but not in either list).Then that letter is added to the list of wrong letters. If that list contains 6 or more letters, a showinfo box states “You Lose!”

4. Implementation details:

a. hangman subclasses Frame

b. you may assume that the user will not edit the Entry’s(this can be prevented but requires more than what we know now).

c. in addition to creating the interface, __init__ should take the given word, make it uppercase, and assign it to self.word

d. each button should set command=cmd, where cmd is a local function accepting one argument that defaults to the same letter on the button label (same thing we did with the calculator).   cmd calls another method click to implement the gameplay above.

Here is an example of how the game works.   First, start the game:

hangman('APPLE') # start with word ‘apple’

tk Word: ????? Right: Wrong A BC DEF S TUV WX

Explanation / Answer

# cook your code here

from Tkinter import *

class HangmanApplication(Frame):

    //initiliazation here

    def __init__(self, master=None):

        Frame.__init__(self, master)

        self.pack()

        self.createWidgets()

    def createWidgets(self):

        self.Abutton = Button(self)

        self. Abutton ["text"] = "A"

        self. Abutton ["fg"]   = "gray"

        self.Abutton["command"] = self.Abutton

        self. Bbutton = Button(self)

        self. Bbutton ["text"] = "B"

        self. Bbutton["fg"]   = "gray"

       self. Cbutton = Button(self)

        self. Cbutton ["text"] = "C"

        self. Cbutton["fg"]   = "gray"

       self. Dbutton = Button(self)

        self. Dbutton ["text"] = "D"

        self. Dbutton["fg"]   = "gray"

        self.Ebutton = Button(self)

        self. Ebutton ["text"] = "E"

        self. Ebutton["fg"]   = "gray"

        self. Fbutton = Button(self)

        self. Fbutton ["text"] = "F"

        self. Fbutton["fg"]   = "gray"

        self. Gbutton = Button(self)

        self. Gbutton ["text"] = "G"

        self. Gbutton["fg"]   = "gray"

        self.Hbutton = Button(self)

        self. Hbutton ["text"] = "H"

        self. Hbutton["fg"]   = "gray"

       self. Ibutton = Button(self)

        self. Ibutton ["text"] = "I"

        self. Ibutton["fg"]   = "gray"

self. Jbutton = Button(self)

        self. Jbutton ["text"] = "J"

        self. Jbutton["fg"]   = "gray"

        self. Kbutton = Button(self)

        self. Kbutton ["text"] = "K"

        self. Kbutton["fg"]   = "gray"

        self. Lbutton = Button(self)

        self. Lbutton ["text"] = "L"

        self. Lbutton["fg"]   = "gray"

        self. Mbutton = Button(self)

        self. Mbutton ["text"] = "M"

        self. Mbutton["fg"]   = "gray"

        self. Nbutton = Button(self)

        self. Nbutton ["text"] = "N"

        self. Nbutton["fg"]   = "gray"

       self. Obutton = Button(self)

        self. Obutton ["text"] = Ö"

        self. 0button["fg"]   = "gray"

        self. Pbutton = Button(self)

        self. Pbutton ["text"] = "P"

        self.Pbutton["fg"]   = "gray"

        self. Qbutton = Button(self)

        self. Qbutton ["text"] = "Q"

        self. Qbutton["fg"]   = "gray"

        self. Rbutton = Button(self)

        self. Rbutton ["text"] = "R"

        self. Rbutton["fg"]   = "gray"

       self. Sbutton = Button(self)

        self. Sbutton ["text"] = "S"

        self. Sbutton["fg"]   = "gray"

        self. Tbutton = Button(self)

        self. Tbutton ["text"] = "T"

        self. Tbutton["fg"]   = "gray"

        self. Ubutton = Button(self)

        self. Ubutton ["text"] = "U"

        self.Ubutton["fg"]   = "gray"

         self. Vbutton = Button(self)

        self. Vbutton ["text"] = "V"

        self. Vbutton["fg"]   = "gray"

        self. Wbutton = Button(self)

        self. Wbutton ["text"] = "W"

        self. Wbutton["fg"]   = "gray"

        self. Xbutton = Button(self)

        self. Xbutton ["text"] = "X"

        self. Xbutton["fg"]   = "gray"

        self. Ybutton = Button(self)

        self. Ybutton ["text"] = "Y"

        self. Ybutton["fg"]   = "gray"

        self. button = Button(self)

        self. Zbutton ["text"] = "Z"

        self. Zbutton["fg"]   = "gray”

        self. Abutton.pack({"side": "left"})

        self. Bbutton.pack({"side": "left"})

        self. Cbutton.pack({"side": "left"})

        self. Dbutton.pack({"side": "left"})

        self. Ebutton.pack({"side": "left"})

        self. Fbutton.pack({"side": "left"})

        self. Gbutton.pack({"side": "left"})

        self. Hbutton.pack({"side": "left"})

        self. Ibutton.pack({"side": "left"})

        self. Jbutton.pack({"side": "left"})

        self. Kbutton.pack({"side": "left"})

        self. Lbutton.pack({"side": "left"})

        self. Mbutton.pack({"side": "left"})

       

        self. Nbutton.pack({"side": "left"})

       

        self. Obutton.pack({"side": "left"})

       

        self. Pbutton.pack({"side": "left"})

       

        self. Qbutton.pack({"side": "left"})

       

        self. Rbutton.pack({"side": "left"})

       

        self. Sbutton.pack({"side": "left"})

       

        self. Tbutton.pack({"side": "left"})

       

        self. Ubutton.pack({"side": "left"})

       

        self. Vbutton.pack({"side": "left"})

       

        self. Wbutton.pack({"side": "left"})

       

        self. Xbutton.pack({"side": "left"})

       

        self. Ybutton.pack({"side": "left"})

       

        self. Zbutton.pack({"side": "left"})

       

   

root = Tk()

app = Application(master=root)

app.mainloop()

root.destroy()