我正在為自己創建一個密碼生成器,我遇到了這個問題。我放了兩個復選框和一個文本輸入。無論我在螢屏上的哪個位置單擊,它都會停用/激活最底部的復選框。你可以運行我的代碼(它是完整的代碼,沒有排除任何東西),看看會發生什么。
.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()
^^ 因為這個問題我還沒有輸入邏輯,請不要專注于給我邏輯。相反,我正在尋找多個復選框問題的解決方案。
.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()
幫助表示贊賞!
uj5u.com熱心網友回復:
問題是CheckBox填充了整個main Screen. 發生這種情況是因為默認size_hint值為(1,1). 嘗試size_hint為您的所有小部件設定一個kv.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/441198.html
標籤:Python python-3.x 基维
上一篇:在Windows中運行pre-commitpython包會給出ExecutableNotFoundError:Executable`/bin/sh`
