I am creating myself a password generator and I have run across this issue. I have put two checkboxes and one text input. Wherever I click on the screen, it deactivates/activates the bottom-most checkbox. You could run my code (it's the full code, nothing excluded) and see what happens.
.py
from kivy.app import App
from kivy.uix.screenmanager import Screen, ScreenManager
import string
sm = ScreenManager()
class main(Screen):
def generate(self):
include_num = self.ids.include_num.active
include_special = self.ids.include_special.active
letters = list(string.ascii_letters)
special = list(string.punctuation)
numbers = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
if self.ids.len_of_password.text:
pass
else:
self.ids.len_of_password.text = 'NEEDED'
class MyApp(App):
def build(self):
sm.add_widget(main(name='main'))
return sm
if __name__ == '__main__':
MyApp().run()
^^ I still haven't put the logic in because of the issue, please do not focus on giving me the logic. Rather, I am looking for a solution for the multiple checkboxes issue.
.kv
<main>
FloatLayout:
Label:
text: 'Length:'
font_size: 70
pos_hint: {'right': 0.85,'y': 0.3}
TextInput:
multiline: False
id: len_of_password
text: '20'
size_hint: 0.3, 0.15
font_size: self.height / 4 * 3
pos_hint: {'x': 0.55, 'y': 0.725}
Label:
text: 'Include numbers?'
font_size: 45
pos_hint: {'right': 0.85, 'y': 0.1}
CheckBox:
active: True
pos_hint: {'x': 0.2, 'y': 0.1}
id: include_num
Label:
text: 'Include special characters?'
font_size: 35
pos_hint: {'right': 0.85, 'top': 0.95}
CheckBox:
active: True
pos_hint: {'x': 0.2, 'top': 0.95}
id: include_special
Button:
text: 'Generate'
font_size: (self.height - len(self.text) * 2) / 2
size_hint: 0.5, 0.2
pos_hint: {'x': 0.25, 'y': 0.1}
on_release: root.generate()
Help is appreciated!
CodePudding user response:
The problem is that the CheckBox
is filling the entire main
Screen
. That happens because the default size_hint
is (1,1)
. Try setting a size_hint
for all the widgets in your kv
.