我正在尝试用kivy创建一个GUI。 为此,我想在按screen1的按钮时更新inputText。 要组织我的页面,我使用的是屏幕管理器。 我基本上想做的是,一旦按下此页面的Button,即在带有id textbox的textInput中输入值。 为此,我开始使用readInValues方法准备一个 ...
提示:本站收集StackOverFlow近2千万问答,支持中英文搜索,鼠标放在语句上弹窗显示对应的参考中文或英文, 本站还提供 中文繁体 英文版本 中英对照 版本,有任何建议请联系yoyou2525@163.com。
我最近开始制作 Kivy 应用程序。
到目前为止它应该做的是将 TextInput 元素从“密码将出现在此处”更改为“已清除!” 当用户按下“清除”按钮时。
不幸的是什么也没发生,我不知道为什么。
代码:
class Main(FloatLayout):
def __init__(self, **kwargs):
super(Main, self).__init__(**kwargs)
self.cols = 2
self.rows = 3
self.add_widget(Label(text=str("Random Password Generator"), size_hint_y=None, pos=(20,600), color=(1, 204/255, 102/255)))
self.checkBox1 = CheckBox(active=False)
self.add_widget(self.checkBox1)
self.dropdown = DropDown()
for index in range(50):
btn = Button(text='%d' % index, pos_hint=(200,200), size_hint_y=None, height=44)
btn.bind(on_release=lambda btn: self.dropdown.select(btn.text))
self.dropdown.add_widget(btn)
self.mainbutton = Button(text='Char Count', size_hint=(0.08, 0.05), pos=(427,400))
self.mainbutton.bind(on_release=self.dropdown.open)
self.add_widget(self.mainbutton)
self.dropdown.bind(on_select=lambda instance, x: setattr(self.mainbutton, 'text', "Char Count: " + x))
self.textBox = TextInput(text="Password will appear here", size_hint=(0.4, 0.05), pos=(427, 520))
self.add_widget(self.textBox)
self.clearButton = Button(text="Clear", size_hint=(0.08,0.05), pos=(427,440))
self.clearButton.bind(on_select=self.clearBox)
self.add_widget(self.clearButton)
def clearBox(self):
self.textBox.text = "Cleared!"
class KeycardApp(App):
def build(self):
return Main()
if __name__ == '__main__':
KeycardApp().run()
如果我是傻子,请随意笑...
通过这样做修复:
self.clearButton.bind(on_release=lambda a: self.clearBox())
更改为 on_release 给了我错误代码“需要 0 个位置参数,但给出了 1 个”,所以我添加了 lambda a: 将参数重新路由到空......并且它起作用了!!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.