正方形型のiconとその下部にテキストが複合したボタンを実装しようとしております。
iconの画像を張り付けたボタンとテキストがあるボタンを組み合わせで下部のコードを実行したところ、ボタンとボタンの境界がはっきりと見えてしまうものとなってしまいました。
iconとテキストを全体として画像化すれば境界がないものを作れるのですがテキストを変更するたびに画像をまた作成しなければならないのでなるべく避けたいです。
下記のコードで境界をなくす方法、もしくはiconとテキストを含むボタンを実装する他の方法があれば教えてもらいたいです。
python
1from kivy.app import App 2from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition 3from kivy.properties import StringProperty, ObjectProperty, BooleanProperty 4from kivy.core.text import LabelBase, DEFAULT_FONT 5 6LabelBase.register(DEFAULT_FONT, "ipaexg.ttf") 7sm = ScreenManager(transition=NoTransition()) 8 9 10class Test(App): 11 12 def build(self): 13 sm.add_widget(TestScreen(name='test')) 14 return sm 15 16class TestScreen(Screen): 17 image = StringProperty('cogwheel-setting.png') 18 print(image) 19 20 def on_enter(self): 21 pass 22 23if __name__ == '__main__': 24 Test().run()
test.kv
test
1<TestScreen>: 2 BoxLayout: 3 orientation: "vertical" 4 canvas.before: 5 Color: 6 rgba: 0.7, 1, 0.3, 1 7 Rectangle: 8 pos: self.pos 9 size: self.size 10 11 Label: 12 size_hint: 1, 1 13 text: 'TITLE' 14 font_size: 150 15 color: 1, 1, 1, 1 16 17 FloatLayout: 18 size_hint: 1, 1 19 pos_hint: {"x":0, "top":0} 20 canvas.before: 21 Color: 22 rgba: 0.7, 1, 0.3, 1 23 Rectangle: 24 pos: self.pos 25 size: self.size 26 BoxLayout: 27 orientation: "horizontal" 28 pos_hint: {"x":0, "top":1} 29 Label: 30 size_hint_x: 4 31 BoxLayout: 32 orientation: "vertical" 33 size_hint_x: 3 34 Button: 35 size_hint_y: 12 36 color: 0, 0, 0, 0 37 background_color: 1, 1, 1, 1 38 Image: 39 size: self.parent.width, self.parent.height 40 y: self.parent.y 41 x: self.parent.x 42 source: root.image 43 FloatLayout: 44 size_hint_y: 2.25 45 Button: 46 pos_hint: {"x":0, "top":1} 47 background_color: 1, 1, 1, 1 48 text:'button text' 49 50 Label: 51 color: 1, 0, 0, 1 52 size_hint_y: 2.25 53 background_color: 0, 0, 0, 1 54 Label: 55 size_hint_x: 4
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/28 08:18