本文整理汇总了Python中kivy.uix.stacklayout.StackLayout.add_widget方法的典型用法代码示例。如果您正苦于以下问题:Python StackLayout.add_widget方法的具体用法?Python StackLayout.add_widget怎么用?Python StackLayout.add_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.stacklayout.StackLayout
的用法示例。
在下文中一共展示了StackLayout.add_widget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def build(self):
lay = StackLayout()
btn = Button(text="hello", width=40, height=40)
btn2 = Button(text="sup", width=40, height=40)
lay.add_widget(btn)
lay.add_widget(btn2)
return lay
示例2: __init__
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def __init__(self, **kwargs):
super(MenuWidget, self).__init__(**kwargs)
default_choice = "demo_tiles"
self.choices = {
"demo_text": "Text drawing",
"demo_bounce": "Basic physics simulation",
"demo_starship": "'Endless' scrolling background and animation",
"demo_tiles": "Tile map scrolling",
"demo_pong": "Simple Pong game",
"demo_breakout": "Breakout implemented with physical mover",
"demo_collision": "Optimized collision checking demo/test",
"demo_collision_1": "Simple collision test case",
"demo_control_1": "Demonstrates a more complex control scheme",
}
layout = StackLayout(orientation="tb-lr", padding=[10, 20, 10, 20])
layout.add_widget(Image(source="assets/img/ui/logo.png", size_hint=(1, 0.4)))
layout.add_widget(Label(text="Choose demo:", size_hint=(1, 0.1)))
self.spinner = Spinner(text=default_choice, values=[x for x in self.choices.iterkeys()], size_hint=(1, 0.1))
layout.add_widget(self.spinner)
self.spinner.bind(text=self.show_selected_value)
self.description_label = Label(text=self.choices[default_choice], valign="middle", halign="center", size_hint=(1, 0.3))
self.description_label.bind(size=self.description_label.setter("text_size"))
layout.add_widget(self.description_label)
run_button = Button(text="Run", size_hint=(1, 0.1))
run_button.bind(state=self.on_run)
layout.add_widget(run_button)
self.add_widget(layout)
示例3: draw_buses
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def draw_buses(self):
"""Adds the buses to the main screen."""
# Clear the screen of any buses.
self.ids.bx_buses.clear_widgets()
# Get a list of just those buses who are included in the filter.
buses = [b for b in self.buses if b["route"] in self.filters]
# Work out the height needed to display all the buses
# (we need this for the StackLayout)
h = (len(buses) * 30)
# Create a StackLayout and ScrollView
sl = StackLayout(orientation="tb-lr", height=h, size_hint=(1, None))
sv = ScrollView(size_hint=(1, 1))
sv.add_widget(sl)
self.ids.bx_buses.add_widget(sv)
# Loop over the buses, create a FinlandArrivals object and add it to the
# StackLayout
for bus in buses:
bs = FinlandArrivals(bus=bus)
if "alert" in(bus):
self.alert = bus["alert"]
sl.add_widget(bs)
示例4: build
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def build(self):
s = StackLayout()
p = MyFilechooser(title = 'test')
b = Button(size_hint = (1,0.2))
b.bind(on_press = p.open)
s.add_widget(b)
return s
示例5: test_stacklayout_nospace
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def test_stacklayout_nospace(self):
# happens when padding is too big
sl = StackLayout()
wgts = [Widget(size_hint=(1., .25)) for i in range(1, 4)]
for wgt in wgts:
sl.add_widget(wgt)
sl.padding = 10
sl.do_layout()
示例6: DragTab
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
class DragTab(BoxLayout):
def __init__(self,**kwargs):
super(DragTab,self).__init__(**kwargs)
#Base Layer is a BoxLayout
#right-hand column is StackLayout, lefthand is a vertical box layout
self.Scrollhome=StackLayout(orientation='tb-rl', size_hint=(.3,1))
#self.Scrollhome.add_widget(Button(text='hi'))
self.lefthand=BoxLayout(orientation='vertical', size_hint=(.7,1))
#within lefthand, stats and a series of semesters
self.Planner=GridLayout(size_hint=(1,.9),rows=2, cols=4, spacing=5)
self.slot1=Semester(text=str(semesters[0]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot1)
self.slot2=Semester(text=str(semesters[2]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot2)
self.slot3=Semester(text=str(semesters[4]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot3)
self.slot4=Semester(text=str(semesters[6]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot4)
self.slot5=Semester(text=str(semesters[1]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot5)
self.slot6=Semester(text=str(semesters[3]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot6)
self.slot7=Semester(text=str(semesters[5]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot7)
self.slot8=Semester(text=str(semesters[7]), color=(0, 0, 1., .2))
self.Planner.add_widget(self.slot8)
self.lefthand.add_widget(self.Planner)
self.lefthand.add_widget(Label(size_hint=(1,.1),text= 'We can display statistics here', color=(1,1,1,.3)))
self.add_widget(self.lefthand)
self.add_widget(self.Scrollhome)
for course in catalog:
self.add_Icon(course)
def add_Icon(self, display):
Icon=DragableButton(text=display,size=(100,100),
droppable_zone_objects=[],
bound_zone_objects=[],
drag_opacity=.5,
remove_on_drag=True)
Icon.bound_zone_objects.append(self.Planner)
Icon.bound_zone_objects.append(self.Scrollhome)
Icon.droppable_zone_objects.append(self.slot1.coursehouse)
Icon.droppable_zone_objects.append(self.slot2.coursehouse)
Icon.droppable_zone_objects.append(self.slot3.coursehouse)
Icon.droppable_zone_objects.append(self.slot4.coursehouse)
Icon.droppable_zone_objects.append(self.slot5.coursehouse)
Icon.droppable_zone_objects.append(self.slot6.coursehouse)
Icon.droppable_zone_objects.append(self.slot7.coursehouse)
Icon.droppable_zone_objects.append(self.slot8.coursehouse)
Icon.droppable_zone_objects.append(self.Scrollhome)
self.Scrollhome.add_widget(Icon)
示例7: build
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def build(self):
root = StackLayout()
custom_widget1 = MyCustomWidget(id='my_custom_widget')
custom_widget1.status = 'ok'
custom_widget2 = MyCustomWidget(id='my_custom_widget')
custom_widget2.status = 'nope'
root.add_widget(custom_widget1)
root.add_widget(custom_widget2)
return root
示例8: build
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def build(self):
oscAPI.init()
main_layout = StackLayout()
for i in range(4):
xy_pad = XyPad(size_hint=(0.5, 0.5))
xy_pad.x_msg = '/fxparam/{0}/value'.format(i*2 + 1)
xy_pad.y_msg = '/fxparam/{0}/value'.format(i*2 + 2)
main_layout.add_widget(xy_pad)
return main_layout
示例9: test_stacklayout_default
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def test_stacklayout_default(self):
# Default orientation is lr-tb.
sl = StackLayout()
wgts = [Widget(size_hint=(.5, .5)) for i in range(4)]
for wgt in wgts:
sl.add_widget(wgt)
sl.do_layout()
self.assertEqual(wgts[0].pos, [0, sl.height / 2.])
self.assertEqual(wgts[1].pos, [sl.width / 2., sl.height / 2.])
self.assertEqual(wgts[2].pos, [0, 0])
self.assertEqual(wgts[3].pos, [sl.width / 2., 0])
示例10: test_stacklayout_padding
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def test_stacklayout_padding(self):
sl = StackLayout()
wgts = [Widget(size_hint=(.5, .5)) for i in range(4)]
for wgt in wgts:
sl.add_widget(wgt)
sl.padding = 5.
sl.do_layout()
self.assertEqual(wgts[0].pos, [5., sl.height / 2.])
self.assertEqual(wgts[1].pos, [sl.width / 2., sl.height / 2.])
self.assertEqual(wgts[2].pos, [5., 5.])
self.assertEqual(wgts[3].pos, [sl.width / 2., 5.])
示例11: test_stacklayout_fixed_size
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def test_stacklayout_fixed_size(self):
sl = StackLayout()
wgts = [Widget(size=(50, 50), size_hint=(None, None))
for i in range(4)]
for wgt in wgts:
sl.add_widget(wgt)
sl.do_layout()
self.assertEqual(wgts[0].pos, [0, sl.height / 2.])
self.assertEqual(wgts[1].pos, [sl.width / 2., sl.height / 2.])
self.assertEqual(wgts[2].pos, [0, 0])
self.assertEqual(wgts[3].pos, [sl.width / 2., 0])
示例12: LogBox
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
class LogBox(ScrollView):
_current_selection = 0
def __init__(self, root):
super(LogBox, self).__init__()
self.root = root
self.size_hint = (1, None)
self.height = 150
self.stack = StackLayout()
self.stack.orientation = 'lr-tb'
self.stack.size_hint = (1, None)
self.stack.bind(minimum_height=self.stack.setter('height'))
self.add_widget(self.stack)
def add(self, note):
self.stack.add_widget(LogEntry(note))
def get_entry(self, at):
if at == 0:
return None
if at > len(self.stack.children):
return None
return self.stack.children[len(self.stack.children)-at]
def get_current_entry(self):
return self.get_entry(self.current_selection)
@property
def current_selection(self):
return self._current_selection
@current_selection.setter
def current_selection(self, value):
for child in self.stack.children:
child.color = [1,1,1,1]
if value > len(self.stack.children):
self._current_selection = 0
return
self._current_selection = value
self.stack.children[len(self.stack.children)-value].color = [1,0,0,1]
# We send a KEY ON signal for each note
# only if we are on play mode.
# Reset done status for each note.
if self.root.app.playing:
for note in self.get_current_entry().notes:
note['done'] = False
arduino.send(str.format("+{0}", note['note']))
示例13: test_stacklayout_spacing
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def test_stacklayout_spacing(self):
sl = StackLayout()
wgts = [Widget(size_hint=(.5, .5)) for i in range(4)]
for wgt in wgts:
sl.add_widget(wgt)
sl.spacing = 10
sl.do_layout()
self.assertEqual(wgts[0].pos, [0, sl.height / 2.])
self.assertEqual(wgts[1].pos, [sl.width / 2. + 5, sl.height / 2.])
self.assertEqual(wgts[2].pos, [0, -10])
self.assertEqual(wgts[3].pos, [sl.width / 2. + 5, -10])
示例14: test_tb_lr_stacklayout
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def test_tb_lr_stacklayout(self):
stacklayout = StackLayout(
orientation='tb-lr',
size=(200, 200),
padding=20,
spacing=10)
widget = Widget(width=100, size_hint=(0.2, 0.4))
stacklayout.add_widget(widget)
stacklayout.do_layout()
self.assertEqual(stacklayout.top - widget.top, 20)
示例15: __init__
# 需要导入模块: from kivy.uix.stacklayout import StackLayout [as 别名]
# 或者: from kivy.uix.stacklayout.StackLayout import add_widget [as 别名]
def __init__(self, **kwargs):
super(MagicTab, self).__init__(**kwargs)
self.text = 'Magic'
tab_magic_ui = StackLayout(orientation='tb-lr',
minimum_width=3100,
padding=(5, 5, 0, 0),
spacing=1)
spells = ["Fireball", "Healing Rain", "Taunt", "Holy Light", "Steady Shot",
"Might", "Strike", "Dance"]
for i in range(0, len(spells)):
spell_string = spells[i]
tab_magic_ui.add_widget(Button(text=spell_string,
size_hint=(.2, .1))) # Width of the buttons
self.add_widget(tab_magic_ui)