python篇-kivy-kv
1,Label
遗留问题:加上 markup: True之后,文本不显示了
解决方法:把text_size和color属性注释掉就出现了
kivytest.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
# coding:utf-8 from kivy.app import App from kivy.uix.floatlayout import FloatLayout from kivy.uix.label import Label class KvTest(FloatLayout): def __init__(self, **kwargs): super().__init__(**kwargs) def label_ref(self, label): print('ref事件被触发了') def label_ref_03(self): print('ref_03事件被触发了') Label class KvTestApp(App): def build(self): return KvTest() if __name__ == '__main__': KvTestApp().run()
kivytest.kv
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<KvTest>: Label: text: '[s][ref=label]AAAA[/ref][/s]' #font_size: '30px' text_size: (100, 100) color: (255,22,1,1) valign: 'top' # 当需要设置标记文本的时候,需要将markup设置为 True # markup: True on_ref_press: root.label_ref(self) print('这是第二个事件。。。。') root.label_ref_03()
2, TabbedPanel
tabbedpanel.py
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
from kivy.app import App from kivy.uix.tabbedpanel import TabbedPanel class TabbedPanelTest(TabbedPanel): def __init__(self,**kwargs): super().__init__(**kwargs) class TabbedPanelApp(App): def build(self): return TabbedPanelTest() if __name__ == '__main__': TabbedPanelApp().run()
tabbedpanel.kv
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<TabbedPanelTest>: size_hint:.5,.5 pos_hint:{'center_x':.5,'center_y':.5} do_default_tab:False TabbedPanelItem: text:'first tab' Label: text:'First tab content area' TabbedPanelItem: text:'tab2' BoxLayout: Label: text:'Second tab content area' Button: text:'Button that dose nothing' TabbedPanelItem: text:'tab3' RstDocument: text: "\n".join(("Hello world","-----------","You are in the third tab."))