我正在使用带有树莓派的python和Kivy库构建一个小型应用程序。
GUI在浮动布局中包含4个文本输入和3个按钮。 问题是,当我单击文本输入光标时,该光标显示并且立即消失。 只有在不释放鼠标单击的情况下,我才能介绍文本。
.kv文件:
<AddStuffMenu>:
FloatLayout:
canvas.before:
Color:
rgba: 1, 1, 1, 1
Rectangle:
pos: self.pos
size: self.size
Button:
text: "Info"
pos_hint: {'center_x': 0.5, 'center_y': .8}
size_hint: .5, .1
font_size: self.height * 0.5
background_color:0,0,0,0
color: 0,0,1,1
enabled : False
TextInput:
size_hint: .2, None
height:30
text:''
pos_hint: {'center_x': 0.5, 'center_y': .7}
multiline: False
hint_text : "code"
id: code
TextInput:
size_hint: .2, None
height:30
text:''
pos_hint: {'center_x': .5, 'center_y': .6}
multiline: False
hint_text : "product"
id: product
TextInput:
size_hint: .2, None
height:30
text:''
pos_hint: {'center_x': .5, 'center_y': .5}
multiline: False
hint_text : "amount"
id: amount
TextInput:
size_hint: .2, None
height:30
text:''
pos_hint: {'center_x': .5, 'center_y': .4}
multiline: False
hint_text : "price"
id: price
Button:
text: "Scan"
pos_hint: {'center_x': .2, 'center_y': .2}
size_hint: .15, .1
font_size: self.height * 0.5
background_color:1, 0, 0, 1
on_press: root.scan()
Button:
text: "Add"
pos_hint: {'center_x': .5, 'center_y': .2}
size_hint: .15, .1
font_size: self.height * 0.5
background_color: 1, 0, 0, 1
on_press: root.add()
Button:
text: "Back"
pos_hint: {'center_x': .8, 'center_y': .2}
size_hint: .15, .1
font_size: self.height * 0.5
background_color: 1, 0, 0, 1
on_press: root.exitScope()
.py文件
class AddStuffMenu(Screen):
def __init__(self,**kwargs):
super (AddStuffMenu,self).__init__(**kwargs)
def exitScope(self,*args):
self.manager.current = 'screenTableData'
def scan(self,*args):
os.system('python /home/pi/barcode.py')
if(os.path.getsize('/home/pi/barcode.txt') > 0):
code = open('/home/pi/barcode.txt', 'r').read()
result = getLineByUPC(code)
if result is not None:
self.ids.codeInput.text = str(result[0])
self.ids.produsInput.text = str(result[1])
else:
popup = Popup(title='INFO', content=Label(text="Produc doesn't exist"), size_hint=(None, None), size=(500, 300), font_size='23sp', valign='justify', haligh='top')
popup.open()
self.ids.code.text = code
else:
popup = Popup(title='INFO', content=Label(text="Try again"), size_hint=(None, None), size=(500, 300), font_size='23sp', valign='justify', haligh='top')
popup.open()
def add(self,*args):
print("AddStuffMenu - add")
print(self.ids.code.text)
print(self.ids.product.text)
print(self.ids.amount.text)
print(self.ids.price.text)
有什么建议吗?
答案 0 :(得分:0)
由于您尚未发布任何代码,很难分辨...
我猜您有一个由onbuttonclick或类似的东西定义的参数。您可能需要添加onbuttonrelease参数。