Skip to content

How to set up a Class #460

Closed Answered by vsquared
vsquared asked this question in Q&A
May 15, 2024 · 3 comments · 8 replies
Discussion options

You must be logged in to vote

This works on my mac:

# Uses Imported mode for py5
_wndW = 400
_wndH = 200

class Button:
# constructor
    def __init__(self, x, y, w, h,rounded, title, btnColor, txtColor):
        self.x = x
        self.y = y
        self.w = w
        self.h = h
        self.rounded = rounded
        self.title = title
        self.btnColor = btnColor
        self.txtColor = txtColor
    
    def display(self):
#  Rect background color
        fill(self.btnColor)
        stroke_weight(2)
        rect(self.x,self.y,self.w,self.h,self.rounded)
#  Text color
        fill(self.txtColor)
        text_size(16)
        text_align(CENTER,CENTER)
        text(self.title, self.x, self.y, self.w, self.h)

def s…

Replies: 3 comments 8 replies

Comment options

You must be logged in to vote
1 reply
@vsquared
Comment options

Comment options

You must be logged in to vote
4 replies
@hx2A
Comment options

@vsquared
Comment options

@hx2A
Comment options

@vsquared
Comment options

Answer selected by villares
Comment options

You must be logged in to vote
3 replies
@vsquared
Comment options

@hx2A
Comment options

@vsquared
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants