如何在Trinket.io/Python中创建随机着色的文本



我正在制作一款名为Gravity code的游戏,游戏的目标是捕捉掉落的物品,这些物品会改变乌龟的颜色、速度、大小或形状。我需要一个随机着色的标题。

# --- imports ---
import turtle
from random import * 
# --- variables ---
font_setup = ("Verdana", 25, "normal")
screen = turtle.Screen()
# --- main ---
title.speed("fastest")
title.hideturtle()
title.penup()
title.goto(-62, 60)
title.write("Gravity", font = font_setup)
title.setpos(-45, 30)
title.write("Code", font = font_setup)
# --- events ---
screen.mainloop()

单击button时,可以使用turtle.onclick(function, mouse_button)执行函数。

CCD_ 3只需要函数的名称而不需要CCD_

on_button_click必须得到两个值——鼠标位置。

import turtle
# --- functions ---
def on_button_click(x, y):
print('button clicked:', x,y)
button.hideturtle()

# --- main ---

screen = turtle.Screen()
button = turtle.Turtle()
button.speed("fastest")
#screen.addshape("icons8-button-100.png") #It's the second button.
#button.shape("icons8-button-100.png") #https://icons8.com/icons/set/button
button.left(90) # The second image is the button I'm using.
button.penup() #It can be resized afer you click download to...
button.goto(0, -120) # 70 x 70 pixels.
button.onclick(on_button_click, 1)
screen.mainloop()

最新更新