【发布时间】:2017-09-11 05:18:32
【问题描述】:
我有一个 kivy 程序,它有一个“sqlite”数据库,其中包含高尔夫比赛的详细信息,它通过标准弹出功能 - pop_mess() 显示信息和警告消息 出于测试目的,我在一个函数中打开了另一个“测试”数据库——set_test_db()。完成此操作后,我想更改弹出窗口的背景颜色以警告用户未使用主数据库。
我已经尝试过这样做(“set_test_db”末尾的代码)。然而,尽管例程正确地检索了当前背景颜色,但它不会改变它。
有人可以指出解决方案的方向吗?编码方法适用于更改小部件的文本属性。 (类似的问题通常是指文本属性)。我已将列表和元组用于颜色值。
在 .ky 文件中
<CustomPopup>:
popup_message: popup_message
size_hint: .98, .75
id: popup_id
title: "Casual and Ancient"
title_align: 'center'
title_color: 1,.5,.3,1
BoxLayout:
id: contentbox
orientation: 'vertical'
TextInput:
id: popup_message
color: .3,.4,1.0,1
background_color: [.7,1.0,.2,1]
text: "text message goes here"
font_size: 16
font_name: 'RobotoMono-Regular'
…..
CaaRoot:
<CaaRoot>:
orientation: 'lr-tb'
padding: 10
etc
...
在 main.py 中
(自我 = CaaRoot) ...
def pop_mess(self,message):
p_up=CustomPopup()
lab=p_up.ids['popup_message']
lab.text=message
p_up.open()
...
def set_test_db(self):
# on button in CaaRoot
# open test data base instead of real
if self.db != None:
print 'Cannot Open Test Data Base - already running'
else:
# open ‘test’ database
# set background colour of popup to warn user.
fn='/home/.... caatestdb.db
self.op_db(fn)
self.testing='TEST database'
p_up=CustomPopup()
lab=p_up.ids['popup_message']
x=lab.background_color
new_col=[.9,.3,.3,1]
lab.background_color=new_col
self.pop_mess('color set to : '+str(new_col)+ ' was : '+str(x))
弹出窗口显示
颜色设置为:[0.9, 0.3, 0.3, 1] 为:[0.7, 1.0, 0.2, 1]
(背景仍设置为 [0.7, 1.0, 0.2, 1])
【问题讨论】:
标签: python properties kivy