Skip to content

Commit 80ba967

Browse files
authored
Merge pull request #2 from Huzaifa-Atiq/input-fixes
Input fixes
2 parents 222caf4 + 75d5069 commit 80ba967

22 files changed

+195
-26
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Other components:
8888
- [Progressbar component](https://github.com/Huzaifa-Atiq/PyUIkit/blob/main/documentation/Progressbar.md)
8989
- [Dropdown component](https://github.com/Huzaifa-Atiq/PyUIkit/blob/main/documentation/Dropdown.md)
9090
- [Switch component](https://github.com/Huzaifa-Atiq/PyUIkit/blob/main/documentation/Switch.md)
91+
- [Checkbox component](https://github.com/Huzaifa-Atiq/PyUIkit/blob/main/documentation/Checkbox.md)
9192
- [Toast component](https://github.com/Huzaifa-Atiq/PyUIkit/blob/main/documentation/Toast.md)
9293

9394
Example Applications:

documentation/Checkbox.md

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Checkbox Component — PyUIkit
2+
3+
A `Checkbox` in PyUIkit lets the user pick **one or more options** independently.
4+
It’s perfect for toggles, settings, and forms where multiple selections are allowed.
5+
6+
Unlike radio buttons, **you can select multiple checkboxes at the same time**.
7+
8+
> ⚠️ **Note:** Before using this component, it is recommended to read the [Quickstart Guide](https://github.com/Huzaifa-Atiq/PyUIkit/blob/main/documentation/Quickstart.md) if you haven't already to understand how to create windows, top-level Divs, and basic setup.
9+
10+
---
11+
12+
## How It Works
13+
14+
* Each checkbox is **independent** and can be toggled on/off.
15+
* You can set a **default state** (checked or unchecked).
16+
* You can **read or change the state dynamically** with static methods.
17+
* Each checkbox is placed individually using `x` and `y` coordinates.
18+
19+
---
20+
21+
## Parameters
22+
23+
| Parameter | Type | Default | Description |
24+
| ------------ | ---- | --------- | -------------------------------------- |
25+
| `text` | str | "" | Label for the checkbox |
26+
| `x`, `y` | int | None | Position of the checkbox |
27+
| `id` | str | None | Unique ID to access this component |
28+
| `text_color` | str | `#ffffff` | Color of the label text |
29+
| `color` | str | `#00ff88` | Checkbox toggle color |
30+
| `font_size` | int | 14 | Label font size |
31+
| `default` | bool | False | Initial checked state (True = checked) |
32+
33+
---
34+
35+
## Static Methods
36+
37+
| Method | Description |
38+
| -------------------------------------- | -------------------------------------------------------------------------------- |
39+
| `Checkbox.is_checked(id)` | Returns `True` if the checkbox is checked, otherwise `False` |
40+
| `Checkbox.set_checked(id, value=True)` | Programmatically sets the checkbox state (`True` = checked, `False` = unchecked) |
41+
42+
---
43+
44+
# Basic Usage
45+
46+
A very simple example showing how to create a single checkbox.
47+
48+
```python
49+
from pyuikit import Body, Div
50+
from pyuikit.components import Checkbox
51+
52+
app = Body(title="Checkbox Example", width=400, height=250)
53+
54+
Div(
55+
x=20,
56+
y=20,
57+
width=300,
58+
height=200,
59+
children=[
60+
Checkbox(
61+
text="Accept Terms",
62+
id="termsCheckbox",
63+
x=10,
64+
y=10
65+
)
66+
]
67+
)
68+
69+
app.run()
70+
```
71+
72+
---
73+
74+
# Intermediate Example — Multiple Checkboxes
75+
76+
```python
77+
from pyuikit import Body, Div, Text
78+
from pyuikit.components import Checkbox
79+
80+
app = Body(title="Multiple Checkbox Example", width=400, height=300)
81+
82+
Div(
83+
x=20,
84+
y=20,
85+
width=350,
86+
height=250,
87+
children=[
88+
Checkbox(
89+
text="Option A",
90+
id="optionA",
91+
x=10,
92+
y=10,
93+
default=True,
94+
text_color='#000000'
95+
),
96+
Checkbox(
97+
text="Option B",
98+
id="optionB",
99+
x=10,
100+
y=50,
101+
text_color='#000000'
102+
),
103+
Checkbox(
104+
text="Option C",
105+
id="optionC",
106+
x=10,
107+
y=90,
108+
text_color='#000000'
109+
),
110+
Text(
111+
text="Check your choices",
112+
id="statusText",
113+
x=10,
114+
y=150,
115+
color="#ffd700",
116+
font_size=14,
117+
text_color='#000000'
118+
)
119+
]
120+
)
121+
122+
app.run()
123+
```
124+
125+
---
126+
127+
# Advanced Example — Dynamic Updates
128+
129+
```python
130+
from pyuikit import Body, Div, Button, Text
131+
from pyuikit.components import Checkbox
132+
133+
def show_selected():
134+
checked = []
135+
for cid in ["optionA", "optionB", "optionC"]:
136+
if Checkbox.is_checked(cid):
137+
checked.append(cid)
138+
Text.set_text("statusText", f"Checked: {', '.join(checked) if checked else 'None'}")
139+
140+
def check_all():
141+
for cid in ["optionA", "optionB", "optionC"]:
142+
Checkbox.set_checked(cid, True)
143+
144+
app = Body(title="Checkbox Update Example", width=400, height=300)
145+
146+
Div(
147+
x=20,
148+
y=20,
149+
width=350,
150+
height=250,
151+
children=[
152+
Checkbox(text="Option A", id="optionA", x=10, y=10,text_color='#000000'),
153+
Checkbox(text="Option B", id="optionB", x=10, y=50,text_color='#000000'),
154+
Checkbox(text="Option C", id="optionC", x=10, y=90,text_color='#000000'),
155+
156+
Button(text="Show Checked", x=10, y=140, on_click=show_selected),
157+
Button(text="Check All", x=150, y=140, on_click=check_all),
158+
159+
Text(text="Waiting...", id="statusText", x=10, y=180, color="#ffd700", font_size=14)
160+
]
161+
)
162+
163+
app.run()
164+
```
165+

documentation/Input.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,16 @@ Div(
122122
# Later in code:
123123

124124
# Get the text
125-
text = Input.get_input(id="msgBox")
125+
text = Input.get_input_text(id="msgBox")
126126

127127
# Set new text
128-
Input.set_input(id="msgBox", value="Hello World!")
128+
Input.set_input_text(id="msgBox", value="Hello World!")
129129

130130
# Change input color (also updates placeholder automatically)
131131
Input.set_input_color(id="msgBox", color="#ff0000")
132132

133+
# Change input color (also updates placeholder automatically)
134+
Input.set_input_bg_color(id="msgBox", color="#ff0000")
135+
133136
```
134137

documentation/Radiobutton.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ Unlike checkboxes, **you cannot select more than one**.
3030
| `default` | str | First option | Default selected value |
3131
| `on_change` | function | None | Called with the new value when selection changes |
3232
| `text_color` | str | `#ffffff` | Label color |
33-
| `font` | str | `'Arial'` | Font family |
3433
| `font_size` | int | `14` | Label font size |
3534

3635
---

documentation/Switch.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ You can also dynamically read or set its state using its `id`.
3535
| `button_color` | `str` | `#ffffff` | Color of the switch button/knob |
3636
| `button_hover_color` | `str` | `None` | Hover color for the switch button |
3737
| `text_color` | `str` | `None` | Color of the label text |
38-
| `font_name` | `str` | `"Arial"` | Font family for the label text |
3938
| `font_size` | `int` | `14` | Font size for the label text |
4039

4140
---

documentation/Text.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ It cannot exist on its own.
2828
| `text` | `str` | *required* | The text to display |
2929
| `x` | `int` | `None` | Absolute X-position (must be used with `y`) |
3030
| `y` | `int` | `None` | Absolute Y-position (must be used with `x`) |
31-
| `font` | `str` | `"Arial"` | Font family |
3231
| `font_size` | `int` | `14` | Text size |
3332
| `color` | `str` | `#000000` | Text color |
3433
| `id` | `str` | `None` | Used for dynamic updates |

documentation/Toast.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ You can **customize colors, position, size, duration, and optional close buttons
3434
| `height` | int | `50` | Height of the toast in pixels |
3535
| `bg_color` | str | `#333333` | Background color of the toast |
3636
| `text_color` | str | `#ffffff` | Color of the text |
37-
| `font_name` | str | `"Arial"` | Font family of the text |
3837
| `font_size` | int | `14` | Font size of the text |
3938
| `show_close` | bool | `True` | Whether to show a close button for manual dismissal |
4039
| `id` | str | None | Unique identifier to access the toast programmatically |

examples/passwordchecker.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ app = Body(title="Password Strength Checker", width=500, height=350, bg_color="#
4444

4545
# ----------------- CHECK FUNCTION -----------------
4646
def check_password():
47-
pwd = Input.get_input(id="pwdInput")
47+
pwd = Input.get_input_text(id="pwdInput")
4848
strength = 0
4949

5050
if len(pwd) >= 8:
0 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)