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()
解决方案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.