Click here to Skip to main content
15,064,166 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Using Canvas from tkinter create the SmileyFace class. This class must have the following functions:

constructor (__init__): draws a smiley face on a canvas object.

wink(smileyFace)

grin(smileyFace)

smile(smileyFace)

sad(smileyFace)

These functions return no values. They modify the look of the SmileyFace object.

Create a main() function that will place a smiley face and five buttons on a Tk() object. The buttons will be labeled as follows:

Smile

Sad

Wink

Grin

Quit

When a button other than the Quit button is clicked, the smiley face will change its appearance according with the button clicked.

For the wink, one eye must change to a line and the grin is a straight line for the face.

What I have tried:

from tkinter import *
class SmileyFace:
def smile():
global mouth
c.delete(mouth)
mouth = c.create_arc(50, 25, 200, 75, start = 180,
extent = 180)
c.create_oval(10, 10, 200, 200, width=2, fill='blue')
#def sad():
#mouth = c.create_arc




win = Tk()
c = Canvas(win)
c.pack()
mouth = c.create_arc(50, 50, 200 ,50, extent = 180)
Button(win, text = 'Smile', command = smile).pack()

(very confused and dont know what to do)

win.mainloop()
Posted
Updated 11-Nov-18 22:41pm
v2

1 solution

You have been given the details of the class and the different functions. Start with the basics: create a single object that draws the smiley, and a button that will call the smile() function. Build and test your code. Once you have that working you should see how to add the other functions and their respective buttons.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900