|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
"Alien"作品代码(拷贝即用):
from tkinter import*
window=Tk()
window.title('Alien')
c=Canvas(window,height=300,width=400)
c.pack()
body=c.create_oval(100,150,300,250,fill='green')
eye=c.create_oval(170,70,230,130,fill='white')
eyeball=c.create_oval(190,90,210,110,fill='black')
mouth=c.create_oval(150,220,250,240,fill='red')
neck=c.create_line(200,150,200,130)
hat=c.create_polygon(180,75,220,75,200,20,fill='blue')
def mouth_open(event):
c.itemconfig(mouth,fill='black')
def mouth_close(event):
c.itemconfig(mouth,fill='red')
def blink(event):
c.itemconfig(eye,fill='green')
c.itemconfig(eyeball,state=HIDDEN)
def unblink(event):
c.itemconfig(eye,fill='white')
c.itemconfig(eyeball,state=NORMAL)
words=c.create_text(200,280,text='I am an alien!')
def steal_hat(event):
c.itemconfig(hat,state=HIDDEN)
c.itemconfig(words,text='Give my hat back!')
def return_hat(event):
c.itemconfig(hat,state=NORMAL)
c.itemconfig(words,text='Thank you!')
c.bind_all('<KeyPress-a>',blink)
c.bind_all('<KeyPress-z>',unblink)
c.bind_all('<KeyPress-d>',steal_hat)
c.bind_all('<KeyPress-k>',return_hat)
c.bind_all('<KeyPress-t>',mouth_open)
c.bind_all('<KeyPress-h>',mouth_close)
可以给些建议,谢谢🙏
(没有用turtle函数,因为不会用,希望有大佬教导,可以看下我的日志,未来可能会改进程序) |
|