بتل کد Battle Codeدارد باز می‌شود…

Two Buttons چالش 7 از جلسه‌ی 7، سخت

دو دکمه روی صفحه بساز: دو Rect، یکی با نوشته‌ی Red و یکی با Blue. با کلیک روی هر کدام، رنگ پس‌زمینه همان رنگ شود. از rect.collidepoint(pos) استفاده کن.

import pgzrun

WIDTH = 500
HEIGHT = 400
red_button = Rect(50, 300, 180, 60)
blue_button = Rect(270, 300, 180, 60)
color = "black"

def draw():
    screen.fill(color)
    # draw the two buttons with their labels

def on_mouse_down(pos):
    global color

pgzrun.go()

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 7: موس · چالش بعدی: Drag the Box

بیشتر بخوان: بازی‌سازی با پایتون و Pygame Zero