4programmers.net

Witaj!

tBane dodał nowy post w wątku: Podstawowe elementy GUI czyli Buttony


Cześć. Uczę się od niedawna ** Python3** i SDL2. Chciałbym stworzyć ładny przycisk - Button. Jak się za to najlepeij zabrać ?
Poniżej zamieszczam ogólny kod przyciski, który działa. Chciałbym dodać ramkę do przycisku i tekst.

Kopiuj
import sdl2 import sdl2.ext import numpy as np  class Button: x : int y : int wdt : int hgh : int r : int g : int b : int  def __init__(self, x : int, y : int, width: int, height: int): self.x = x self.y = y self.wdt = width self.hgh = height  self.set_color(64, 64, 64)  def set_color(self, r : int, g : int, b : int): self.r = r self.g = g self.b = b  def cursorHover(self, mouse_x : int, mouse_y : int) -> bool: if( mouse_x >= self.x and mouse_y >= self.y and mouse_x <= self.x + self.wdt and mouse_y <= self.y + self.hgh): self.set_color(128, 128, 128) return True else: self.set_color(64, 64, 64) return False;  def draw(self, renderer):  renderer.color = sdl2.ext.Color(self.r, self.g, self.b) rect = sdl2.SDL_Rect(self.x, self.y, self.wdt, self.hgh) rect = sdl2.SDL_ renderer.fill(rect) 


Zobacz post

Z poważaniem,
4programmers.net

Jeżeli masz problemy z kliknięciem na przycisk "Zobacz post", skopiuj i wklej poniższy link w przeglądarce:

http://4programmers.net/Notification?path=%252FForum%252FGamedev%252F376509-podstawowe_elementy_gui_czyli_buttony%253Fp%253D2003479%2523id2003479