Last active
March 15, 2017 14:58
-
-
Save ilovetogetspamed/f19099f91abf6fa7f041a4d195bf92f8 to your computer and use it in GitHub Desktop.
Can't Get my checkbox to check/uncheck
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from kivy.base import runTouchApp | |
from kivy.lang import Builder | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.uix.checkbox import CheckBox | |
class NetworkConfig(BoxLayout): | |
def __init__(self, *args, **kwargs): | |
super(NetworkConfig, self).__init__(*args, **kwargs) | |
# def on_checkbox_active(self, checkbox, value): | |
# if value: | |
# print('The checkbox', checkbox, 'is active') | |
# else: | |
# print('The checkbox', checkbox, 'is inactive') | |
widget = Builder.load_string(""" | |
NetworkConfig: | |
orientation: 'vertical' | |
cols: 1 | |
# rows: 1 | |
canvas: | |
Color: | |
rgba: 0.3, 0.3, 0.3, 1 | |
Rectangle: | |
size: self.size | |
pos: self.pos | |
Label: | |
text: '[b]Network Configuration[/b]' | |
markup: True | |
size_hint_y: 0.1 | |
background_normal: None | |
GridLayout: | |
rows: 8 | |
padding: dp(8) | |
spacing: dp(16) | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 1 | |
cols: 2 | |
size_hint_y: 0.9 | |
Label: | |
text: "Host Name" | |
TextInput: | |
id: hostname | |
multiline: False | |
hint_text: 'hostname@example.com' | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 2 | |
cols: 2 | |
size_hint_y: 0.1 | |
Label: | |
text: 'Automatic setup using DHCP' | |
CheckBox: | |
id: inet_use_dhcp | |
value: True | |
active: True | |
on_active: root.on_checkbox_active() | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 1 | |
cols: 2 | |
Label: | |
text: "IP Address" | |
TextInput: | |
id: inet_address | |
multiline: False | |
hint_text: '192.168.1.100' | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 1 | |
cols: 2 | |
Label: | |
text: "Network Mask" | |
TextInput: | |
id: inet_mask | |
multiline: False | |
hint_text: '255.255.255.0' | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 1 | |
cols: 2 | |
Label: | |
text: "Default Gateway" | |
TextInput: | |
id: inet_bcast | |
multiline: False | |
hint_text: '192.168.1.1' | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 1 | |
cols: 2 | |
Label: | |
text: "DNS 1" | |
TextInput: | |
id: inet_dns1 | |
multiline: False | |
hint_text: 'dns1@example.com' | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 1 | |
cols: 2 | |
Label: | |
text: "DNS 2" | |
TextInput: | |
id: inet_dns2 | |
multiline: False | |
hint_text: 'dns2@example.com' | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 1 | |
cols: 2 | |
Label: | |
text: "DNS 3" | |
TextInput: | |
id: inet_dns3 | |
multiline: False | |
hint_text: 'dns3@example.com' | |
""") | |
runTouchApp(widget) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from kivy.base import runTouchApp | |
from kivy.lang import Builder | |
from kivy.uix.boxlayout import BoxLayout | |
from kivy.uix.checkbox import CheckBox | |
class NetworkConfig(BoxLayout): | |
def __init__(self, *args, **kwargs): | |
super(NetworkConfig, self).__init__(*args, **kwargs) | |
def on_checkbox_active(self, checkbox, value): | |
if value: | |
print('The checkbox', checkbox, 'is active') | |
else: | |
print('The checkbox', checkbox, 'is inactive') | |
class UseDHCP(CheckBox): | |
pass | |
widget = Builder.load_string(""" | |
NetworkConfig: | |
orientation: 'vertical' | |
cols: 1 | |
rows: 1 | |
Label: | |
text: '[b]Network Configuration[/b]' | |
markup: True | |
size_hint_y: 0.1 | |
background_normal: None | |
GridLayout: | |
cols: 1 | |
GridLayout: | |
padding: dp(8) | |
spacing: dp(16) | |
rows: 2 | |
cols: 2 | |
size_hint_y: 0.1 | |
Label: | |
text: 'Automatic setup using DHCP' | |
UseDHCP: | |
id: use_dhcp | |
active: True | |
on_active: root.on_checkbox_active(self, self.state) | |
""") | |
runTouchApp(widget) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment