Created
June 29, 2015 21:59
-
-
Save kived/dd6ffd40d672e35abf56 to your computer and use it in GitHub Desktop.
Kivy: dock demo without kv
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kivy | |
kivy.require('1.9.0') | |
from kivy.app import App | |
from kivy.uix.anchorlayout import AnchorLayout | |
from kivy.uix.stacklayout import StackLayout | |
from kivy.uix.button import Button | |
from kivy.uix.widget import Widget | |
from kivy.metrics import dp | |
class TestApp(App): | |
def build(self): | |
root = AnchorLayout(anchor_x='left') | |
sl = StackLayout(orientation='lr-tb', size_hint=(None, None), width=1) | |
sl.bind(minimum_height=sl.setter('height')) | |
def update_button_size(inst, size): | |
inst.width = size[0] + dp(12) | |
inst.height = size[1] + dp(12) | |
b1 = Button(text='Hello, this is a long message here', size_hint=(None, None)) | |
b1.bind(texture_size=update_button_size) | |
b2 = Button(text='Hello world', size_hint=(None, None)) | |
b2.bind(texture_size=update_button_size) | |
sep = Widget(size_hint_y=None, height=dp(12)) | |
b3 = Button(text='Bye', size_hint=(None, None)) | |
b3.bind(texture_size=update_button_size) | |
sl.add_widget(b1) | |
sl.add_widget(b2) | |
sl.add_widget(sep) | |
sl.add_widget(b3) | |
root.add_widget(sl) | |
return root | |
if __name__ == '__main__': | |
TestApp().run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment