Skip to content

Instantly share code, notes, and snippets.

@gottadiveintopython
Last active October 10, 2018 06:45
Show Gist options
  • Save gottadiveintopython/c5e76cadac57d26d29fe29c0892e470c to your computer and use it in GitHub Desktop.
Save gottadiveintopython/c5e76cadac57d26d29fe29c0892e470c to your computer and use it in GitHub Desktop.
あえてpos_hintを使わずに中央揃えを試みる
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string('''
FloatLayout:
Button:
text: 'Kivy'
center: root.center
'''))
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string('''
FloatLayout:
Button:
text: 'Kivy'
size_hint: None, None
center: root.center
'''))
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string('''
FloatLayout:
Button:
text: 'Kivy'
size_hint: None, None
size: root.size
center: root.center
'''))
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.factory import Factory
root = Factory.FloatLayout()
button = Factory.Button(text='Kivy', size_hint=(None, None, ))
root.add_widget(button)
root.bind(size=button.setter('size'), center=button.setter('center'))
runTouchApp(root)
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
runTouchApp(Builder.load_string('''
Widget:
Button:
text: 'Kivy'
size_hint: None, None
size: root.size
center: root.center
'''))
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
root = Builder.load_string('''
FloatLayout:
Button:
text: 'Kivy'
x: root.center_x - self.width / 2
y: root.center_y - self.height / 2
size_hint: .5, .5
''')
runTouchApp(root)
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
root = Builder.load_string('''
FloatLayout:
Button:
text: 'Kivy'
right: root.center_x + self.width / 2
top: root.center_y + self.height / 2
size_hint: .5, .5
''')
runTouchApp(root)
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
root = Builder.load_string('''
FloatLayout:
Button:
text: 'Kivy'
center_x: root.center_x + self.width * 0
center_y: root.center_y + self.height * 0
size_hint: .5, .5
''')
runTouchApp(root)
from kivy.config import Config
Config.set('graphics', 'width', 400)
Config.set('graphics', 'height', 300)
from kivy.app import runTouchApp
from kivy.lang import Builder
root = Builder.load_string('''
FloatLayout:
Button:
text: 'Kivy'
center: root.center or self.size
size_hint: .5, .5
''')
runTouchApp(root)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment