importturtle,random
s=turtle.Screen()
#s.screensize(900,700)#设置窗口大小
s.setup(800,600,100,50)#设置窗口大小及初始左上角坐标
#添加背景与画笔
s.bgpic('images/91.png')
hands =['images/1.gif','images/2.gif','images/3.gif']
commands =['images/begin.gif','images/end.gif']
foriinhands:
s.addshape(i)
foriincommands:
s.addshape(i)
print(s.getshapes())
#设置各画笔位置和初始造型
p=turtle.Pen()
p.penup()
p.goto(-150,120);p.write('用 户',font=('隶书',20))
p.goto(150,120);p.write('计算机',font=('隶书',20))
p.ht()
myhand=turtle.Pen(shape='images/1.gif')
button=turtle.Pen(shape='images/begin.gif')
computer = turtle.Pen(shape='images/3.gif')
myhand.up()
computer.up()
button.up()
myhand.goto(-150,)
computer.goto(150,)
button.goto(,-200)
pw=turtle.Pen()
pw.pu()
pw.goto(-50,);pw.pencolor('red')
#设置事件和相应函数
but_i =
defcomputer_fun():
pw.clear()
whilebut_i ==1:
computer.shape(random.choice(hands))
#print(myhand.shape)
ifmyhand.shape()==computer.shape():
pw.write('胜利',font=('隶书',50))
else:
pw.write('失败',font=('隶书',50))
defbut_click(x,y):
globalbut_i
ifbut_i==:
but_i =1
button.shape('images/end.gif')
else:
but_i=
button.shape('images/begin.gif')
computer_fun()
defmyhand_fun(x,y):
myhand.shape(random.choice(hands))
myhand.onclick(myhand_fun,btn=1)
button.onclick(but_click,btn=1)
s.mainloop()
领取专属 10元无门槛券
私享最新 技术干货