使用Python tkinter创建一个笑脸 [英] Create a smiley face using Python tkinter

查看:639
本文介绍了使用Python tkinter创建一个笑脸的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用来自tkinter的Canvas创建SmileyFace类。这个类必须具有以下功能:



构造函数(__init__):在画布对象上绘制一个笑脸。



眨眼(smileyFace)



笑脸(笑脸)



微笑(smileyFace)



悲伤(smileyFace)



这些函数不返回值。它们修改了SmileyFace对象的外观。



创建一个main()函数,它将在Tk()对象上放置一个笑脸和五个按钮。按钮将标记如下:



微笑



悲伤



Wink



Grin



退出



当点击退出按钮以外的按钮时,笑脸会根据点击的按钮改变其外观。



For眨眼,一只眼睛必须换成一条线,笑容是一条直线。



我尝试了什么:


来自tkinter进口的
*

类SmileyFace:

def smile():

全球嘴巴

c.delete(嘴巴)

口= c.create_arc(50,25,200,75,开始= 180,

范围= 180)

c.create_oval(10,10,200,200,width = 2,fill ='blue')

#def sad():

#mouth = c.create_arc









win = Tk()

c =画布(赢)

c.pack()

mouth = c .create_arc(50,50,200,50,extent = 180)

Button(win,text ='Smile',command = smile).pack()



(非常困惑,不知道该怎么做)



win.mainloop()

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()

推荐答案

您已经获得了类和不同函数的详细信息。从基础开始:创建一个绘制笑脸的对象,以及一个调用smile()函数的按钮。构建并测试您的代码。一旦你开始工作,你应该看看如何添加其他功能及其各自的按钮。
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.


这篇关于使用Python tkinter创建一个笑脸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆