Skip to content

card

pdwidgets.widgets.card

Card container widget.

Card(parent, x=0, y=0, w=None, h=None, align=None, align_to=None, fg=None, bg=None, visible=True, value=None, padding=None, radius=8, shadow=2, title=None, font=None)

Bases: Widget

Rounded container with optional title and drop shadow.

Initialize a Card: a rounded, optionally-shadowed container for grouping other widgets.

The card paints a rounded surface rectangle (with a cheap fake drop shadow) and, optionally, a title along its top. Add child widgets to it exactly like any other container.

Parameters:

Name Type Description Default
parent Widget

The parent widget or screen that contains this card.

required
x int

The x-coordinate of the card.

0
y int

The y-coordinate of the card.

0
w int

The width of the card.

None
h int

The height of the card.

None
align int

The alignment of the card.

None
align_to Widget

The widget to align to.

None
fg int

The foreground (text) color; defaults to on_surface.

None
bg int

The card surface color; defaults to surface.

None
visible bool

The visibility of the card.

True
value Any

User-assigned value of the card.

None
padding tuple

The padding on each side of the card.

None
radius int

The corner radius of the card (default is 8).

8
shadow int

Fake drop-shadow offset in pixels (0 disables).

2
title str

Optional title drawn along the top of the card.

None
font module

Optional proportional font module for the title.

None
Usage

card = Card(screen, w=200, h=120, title="Settings") Switch(card, align=pd.ALIGN.CENTER)

draw(area=None)

Draw the card's shadow and rounded surface.

When a child asks the card to repaint just its sub-area (via parent.draw(child.area)), only that region is refilled with the card color so sibling widgets are not erased; a full (area is None) draw repaints the shadow and rounded surface.