本文整理汇总了Python中kivy.uix.relativelayout.RelativeLayout.add_widget方法的典型用法代码示例。如果您正苦于以下问题:Python RelativeLayout.add_widget方法的具体用法?Python RelativeLayout.add_widget怎么用?Python RelativeLayout.add_widget使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kivy.uix.relativelayout.RelativeLayout
的用法示例。
在下文中一共展示了RelativeLayout.add_widget方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: build
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def build(self):
## SM = ScreenManager(transition=NoTransition())
## SM.add_widget(ClusterDetailsScreen(name='cluster details'))
global SM
window=RelativeLayout()
SM = ClusterDetailsScreen()
window.add_widget(SM)
picto = SM.ids['pictoPanel']
bubble = SM.ids['bubblePanel']
specs = SM.ids['specsPanel']
#'left_top', 'left_mid', 'left_bottom',
#'top_left', 'top_mid', 'top_right',
#'right_top', 'right_mid', 'right_bottom',
#'bottom_left', 'bottom_mid', 'bottom_right'
c1=Comment("capabilities of\nthe cluster in\nlayman's terms", \
(10,100),(152,89),'top_mid')
c2=Comment("adequate size +\nuniform strokes =\nreadable font", \
(20,390),(175,90),'bottom_left')
c3=Comment("1 square falling into \nplace = 4 nodes\nchanging status", \
(150,230),(207,80),'right_bottom')
c4=Comment("1 circle = 1 job with\ndiameter, position, color,\nand transparency\nreflecting job\ncharacteristics", \
(420,200),(245,120),'right_bottom')
c5=Comment("The circles rise like\nbubbles as they\napproach completion,\nfinally floating away\nwhen they finish.", \
(690,360),(198,140),'bottom_left')
c6=Comment("scrolling banner with\nhyperlinks that direct\nto the user's website", \
(100,10),(230,80),'right_bottom')
c7=Comment("Bar graphs depict\ndifferences more\nclearly than pie\n charts[2].", \
(210,500),(170,110),'bottom_right')
c8=Comment("Click on a circle\nto see job details.", \
(710,230),(180,60),'left_mid')
c9=Comment("color-blind-\nfriendly palette", \
(420,450),(160,60),'right_bottom')
comments=[c1,c2,c3,c4,c5,c6,c7,c8,c9]
for x in comments:
window.add_widget(x)
specs.ids['details'].text = SM.importText('melete.rst')
SM.ids['banner'].text = SM.importText('users.rst')
Clock.schedule_once(self.scrollBanner)
Clock.schedule_once(c1.appear,12)
Clock.schedule_once(c2.appear,24)
Clock.schedule_once(c3.appear,36)
Clock.schedule_once(c4.appear,48)
Clock.schedule_once(c5.appear,60)
Clock.schedule_once(c6.appear,72)
Clock.schedule_once(c7.appear,84)
Clock.schedule_once(c8.appear,96)
Clock.schedule_once(c9.appear,108)
Clock.schedule_interval(self.scrollBanner, 60)
Clock.schedule_interval(picto.addNodes, .1)
Clock.schedule_interval(picto.moreNodes, 5)
Clock.schedule_once(bubble.addJobs)
Clock.schedule_interval(bubble.progress, 6.1)
return window
示例2: FIT3140Ui
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
class FIT3140Ui(BoxLayout):
def __init__(self, maze, robotController, **kwargs):
super(self.__class__,self).__init__(**kwargs)
self.app = kivy.app.App.get_running_app()
self.maze = maze
self.robotController = robotController
self.robot = self.robotController.robot
self.mazeViewFloat = RelativeLayout()
self.mazeView = MazeView(self.maze, self.robot, self.mazeViewFloat)
self.mazeViewFloat.add_widget(self.mazeView)
self.workspaceLayout = BoxLayout(orientation="vertical", size_hint=(1, .9))#will contain a 'begin' button and label
self.beginButton = Button(text="Begin", size_hint=(1, .1))#run the tree
self.beginButton.bind(on_press=self.app.runProgram)
self.workspace = FCodeWorkspace()
self.workspaceLayout.add_widget(self.workspace)
self.workspaceLayout.add_widget(self.beginButton)
#add all the things to the main screen
self.add_widget(Palette(workspace=self.workspace))#add the palette
self.add_widget(self.workspaceLayout)#add the workspace
self.add_widget(self.mazeViewFloat)#add the maze
示例3: add_widget
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def add_widget(self, widget, index=0):
slide = RelativeLayout(size=self.size, x=self.x - self.width, y=self.y)
slide.add_widget(widget)
super(Carousel, self).add_widget(slide, index)
if index != 0:
self.slides.insert(index - len(self.slides), widget)
else:
self.slides.append(widget)
示例4: __init__
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def __init__(self, **kwargs):
super(ChessboardUI, self).__init__(**kwargs)
game = kwargs.get('game', None)
# left numbers
left_box = BoxLayout(orientation='vertical', size_hint_x=None, width=dp(30))
for n in range(8, -1, -1):
if n == 0:
left_box.add_widget(Label())
break
left_box.add_widget(Label(text=str(n), color=(0,0,0,1)))
# right numbers
right_box = BoxLayout(orientation='vertical', size_hint_x=None, width=dp(30))
for n in range(8, -1, -1):
if n == 0:
right_box.add_widget(Label(size_hint_y=None, height=dp(30)))
break
right_box.add_widget(GridLabelOpponent(text=str(n), color=(0,0,0,1)))
main_box = BoxLayout(orientation='vertical')
merge_layers = RelativeLayout()
background_grid = ChessboardGrid()
self.actual_board = Chessboard(game=game)
self.actual_board.bind(move_made=self.set_moves)
merge_layers.add_widget(background_grid)
merge_layers.add_widget(self.actual_board)
bottom_box = BoxLayout(size_hint_y=None, height=dp(30))
for c in ('a','b','c','d','e','f','g','h'):
bottom_box.add_widget(Label(text=c, color=(0,0,0,1)))
top_box = BoxLayout(size_hint_y=None, height=dp(30))
for c in ('','a','b','c','d','e','f','g','h',''):
if not c:
top_box.add_widget(Label(size_hint_x=None, width=dp(30)))
continue
top_box.add_widget(GridLabelOpponent(text=c))
main_box.add_widget(merge_layers)
main_box.add_widget(bottom_box)
except_top = BoxLayout()
except_top.add_widget(left_box)
except_top.add_widget(main_box)
except_top.add_widget(right_box)
self.orientation = 'vertical'
self.add_widget(top_box)
self.add_widget(except_top)
self.labels = [bottom_box, top_box, left_box, right_box]
self.bind(minimize=self.min, all_moves=self.change_board_moves)
示例5: __init__
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def __init__(self):
super(MainWidget, self).__init__()
songpath1 = 'together-we-are.wav'
songpath2 = 'lionhearted.wav'
self.selection = Selection()
song1 = Song(songpath1, song1_structure, self.selection)
song2 = Song(songpath2, song2_structure, self.selection)
self.beatgen = BeatwiseGenerator()
self.beatgen.add_song(song1)
self.beatgen.add_song(song2)
audio = Audio()
audio.add_generator(self.beatgen)
self.selection.beatgen = self.beatgen
self.clock = ClassClock()
self.conductor = Conductor(self.clock)
self.scheduler = Scheduler(self.conductor)
self.conductor.set_bpm(128)
#info = Label(text = "text", pos=(0, 500), text_size=(100,100), valign='top')
#self.add_widget(info)
# root = ScrollView(size_hint=(None, None), size=(800, 600),
# pos_hint={'center_x': .5, 'center_y': .5})
# self.add_widget(root)
#self.rel = AnchorLayout(size_hint=(None, None), width=9000, pos_hint={'center_x': .5, 'center_y': .5},
# anchor_x='left', anchor_y='top')
self.rel = RelativeLayout(size_hint=(None, None), width=9000, pos_hint={'center_x': .5, 'center_y': .5})
self.add_widget(self.rel)
# anchor = AnchorLayout(anchor_x='left', anchor_y='top')
# self.rel.add_widget(anchor)
layout = GridLayout(cols=1, padding=50, spacing=50, size_hint=(None, None), width=9000, row_force_default=True,
row_default_height=100)
self.rel.add_widget(layout)
for song in self.beatgen.get_songs():
container = RelativeLayout()
layout.add_widget(container)
container.add_widget(song)
self.nowline = Nowline(self.scheduler)
self.rel.add_widget(self.nowline)
self.beatgen.nowline = self.nowline
示例6: buildUI
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def buildUI(self):
bottomBox = RelativeLayout() # 1024,188
self.screenManager = KYRScreenManager(size=(1024,512), size_hint=(None,None))
self.info = TextInput(text=self.infoText, multiline=True, readonly=True, size=(1014,30), size_hint=(None,None), pos=(6,152))
btnMenu = Button(text='menu', size=(200,140), size_hint=(None,None), pos=(6,6))
bottomBox.add_widget(self.info)
bottomBox.add_widget(btnMenu)
self.add_widget(self.screenManager)
self.add_widget(bottomBox)
示例7: ColorPickerBox
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
class ColorPickerBox(RelativeLayout):
def __init__(self, popupwindow, **kwargs):
super(ColorPickerBox, self).__init__(**kwargs)
self.popupwindow = popupwindow
self.generator = RelativeLayout(
size_hint = (None, None),
width = "400dp",
height = "200dp",
pos = ["50dp", "100dp"] #"50dp"
)
self.acw = AutonomousColorWheel(self)
self.generator.add_widget(self.acw)
self.gpi = ColoredTextInput(pos = ["230dp", "80dp"])
self.generator.add_widget(self.gpi)
self.add_widget(self.generator)
self.create_btn = Button(
size_hint = [None, None],
size = ["100dp","30dp"],
pos = ["320dp","10dp"]
)
self.create_btn.bind(on_release=self.create_group)
self.cancel_btn = Button(
size_hint = [None, None],
size = ["100dp","30dp"],
pos = ["200dp","10dp"]
)
self.cancel_btn.bind(on_release=self.cancel_creation)
self.add_widget(self.cancel_btn)
self.add_widget(self.create_btn)
def create_group(self, instance):
print("creation")
self.popupwindow.change_group()
self.popupwindow.dismiss()
def cancel_creation(self, instance):
print("cancel creation")
self.popupwindow.dismiss()
def color_change(self, rgba):
self.gpi.back_color = rgba
示例8: add_widget
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def add_widget(self, widget, index=0):
#replacing index by z-index
#a = RelativeLayout.add_widget(self, widget, getattr(widget,'z',0))
#Duplicate pointer to template
widget.template = self
#Re order them according to z elt:
cs = self.children[:]
cs.append(widget)
cs.sort(key= lambda x: getattr(x,'z',0))
self.clear_widgets()
for c in cs:
RelativeLayout.add_widget(self,c)
self.children = cs
示例9: buildUI
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def buildUI(self):
bottomBox = RelativeLayout() # 1024,188
self.screenManager = KYRScreenManager(size=(1068,450), size_hint=(None,None), pos=(25,224))
self.info = Info(text=self.infoText, multiline=True,
readonly=True, size=(1064,30), size_hint=(None,None), pos=(25,167))
btnMenu = Button(text='menu', size=(196,120), size_hint=(None,None), pos=(28,16), opacity = .5)
self.inventory = GridLayout(orientation='vertical',cols=5,pos=(333,-562),spacing=15)
bottomBox.add_widget(self.info)
bottomBox.add_widget(btnMenu)
self.add_widget(self.inventory)
self.add_widget(self.screenManager)
self.add_widget(bottomBox)
self.buildInventory()
示例10: _generateMap
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def _generateMap(self):
layout = RelativeLayout()
self.mapImg=Image(source='resources/images/map.png',allow_stretch = True, keep_ratio = False)
self.mapPin = MapPin( parent=self.mapImg,view = self,allow_stretch = False, source='resources/images/pin.png', size=(20,34))
self.mapImg.add_widget(self.mapPin)
layout.add_widget(self.mapImg)
print "Scheduling."
# Clock.schedule_interval(self._updateMapImg, 2)
Clock.schedule_interval(self._timeseriesGenerated, 2)
return layout
示例11: GameOver
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
class GameOver(Popup):
def __init__(self, root_widget, **kw):
super(GameOver, self).__init__(**kw)
self.root_widget = root_widget
self.title = 'GAME OVER'
self.layout = RelativeLayout()
self.btn_new_game = Button(text='New Game', size_hint=(.5,.1), pos_hint={'center_x':.25, 'center_y': .05})
self.btn_new_game.bind(on_press=self.new_game)
self.btn_exit = Button(text='Exit', size_hint=(.5,.1), pos_hint={'center_x':.75, 'center_y': .05})
self.btn_exit.bind(on_press=self.root_widget.close_app)
self.lbl_score = Label(size_hint=(.5,.1), pos_hint={'center_x':.5, 'center_y': .4})
self.lbl_high_score = Label(size_hint=(.5,.1), pos_hint={'center_x':.5, 'center_y': .7})
self.layout.add_widget(self.lbl_score)
self.layout.add_widget(self.lbl_high_score)
self.layout.add_widget(self.btn_new_game)
self.layout.add_widget(self.btn_exit)
self.content = self.layout
self.size_hint = (None, None)
self.size = (400, 400)
def set_score(self, score):
high_score = load_data('data/score.txt')
if score > high_score:
high_score = score
write_data('data/score.txt', score)
self.lbl_score.text = 'Score: %s' % score
self.lbl_high_score.text = 'High Score: %s' % high_score
def new_game(self, *args):
self.dismiss()
self.root_widget.new_game()
示例12: BiscuitsApp
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
class BiscuitsApp(App):
def __init__(self):
super().__init__()
self.widget = RelativeLayout()
self._scene = None
self.input = Input()
self.game = BiscuitsGame(self)
@property
def scene(self):
return self._scene
@scene.setter
def scene(self, scene):
if self._scene:
self._scene.unload()
self.widget.remove_widget(self._scene.widget)
self._scene = scene
self.widget.add_widget(scene.widget)
def load_scene(self, loadpoint_ID):
loadpoint = loadpoints[loadpoint_ID]
if loadpoint.type == 'dead':
self.scene = DeadScene(self)
elif loadpoint.type == 'start':
self.scene = StartScene(self)
elif loadpoint.type == 'comic':
self.scene = ComicScene(self, loadpoint)
else:
self.scene = self.game.load(loadpoint)
def update(self, dt):
self.input.update(dt)
self.scene.update(dt)
def build(self):
EventLoop.ensure_window()
self.load_scene('Loadpoint 1a')
Clock.schedule_interval(self.update, 1.0 / 60.0)
return self.widget
示例13: __init__
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
class Region:
def __init__(self, loader, region_config):
self.loader = loader
self.widget = RelativeLayout()
self.objects = set()
for tile in region_config.tiles:
self.widget.add_widget(tile.image)
for ID in region_config.object_IDs:
self.load_object(ID)
self._to_cleanup = []
def update(self, dt):
for obj in self.objects:
obj.signals.update.send(dt)
while self._to_cleanup:
obj = self._to_cleanup.pop()
self.objects.remove(obj)
# TODO consider using weakref.finalize
try:
self.widget.remove_widget(obj.widget._kivy_widget)
except AttributeError:
pass
def load_object(self, ID):
obj = self.loader.load(ID)
obj.signals.destroy.connect(self.cleanup)
self.objects.add(obj)
try:
# TODO clean up this widget stuff
self.widget.add_widget(obj.widget._kivy_widget)
except AttributeError:
pass
def cleanup(self, obj):
self._to_cleanup.append(obj)
示例14: addButton
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
def addButton(self,text='',btntxt = '',callback=None):
entrysize = [0,0]
horiz = RelativeLayout(size_hint= (1.0,None))#orientation = 'lr-tb',padding=(5,5,5,5))
newtext = Label(text=text,markup=True, size_hint= (1.0,None) )
newtext.texture_update()
newtext.size = newtext.texture_size
newtext.size_hint = (None,None)
entrysize = [ entrysize[0] + newtext.width , max(entrysize[1],newtext.height) ]
#horiz.center = (Window.width/2,-entrysize[1]/2)
#(Window.width/2-entrysize[0]/2-5, -entrysize[1]/2) #- newtext.width
btn = Button(text=btntxt)
if callback is not None: btn.bind(on_press=callback)
btn.size_hint = (None,None)
btn.texture_update()
btn.size = btn.texture_size
print newtext.size, btn.size
btn.width += 10
btn.height += 10
entrysize = [ entrysize[0] + btn.width , max(entrysize[1], btn.height) ]
horiz.size=(entrysize[0],entrysize[1]+7)
btn.center = (Window.width/2 + btn.width/2+5, btn.height/2+5) #- newtext.width
newtext.center = (Window.width/2 - newtext.width/2-5,btn.height/2+5)#(Window.width/2-newtext.width/2-5,-entrysize[1]/2)
#horiz.size = (entrysize[0], entrysize[1])
print entrysize
#horiz.center = (Window.width/2,-entrysize[1]/2)
horiz.add_widget(newtext)
horiz.add_widget(btn)
self.verticality += entrysize[1]+7
self.size = (Window.width,self.verticality)
self.add_widget(horiz)
print self.verticality
示例15: ButtonPad
# 需要导入模块: from kivy.uix.relativelayout import RelativeLayout [as 别名]
# 或者: from kivy.uix.relativelayout.RelativeLayout import add_widget [as 别名]
class ButtonPad(Widget):
def __init__(self, **kw):
super(ButtonPad, self).__init__(**kw)
self.listeners = []
self.layout = RelativeLayout()
self.add_widget(self.layout)
btn_ids = ['A', 'B', 'X', 'Y']
btn_pos = [(.8, .5), (.5, .2), (.5, .8), (.2, .5)]
btn_colors = [[.7,0,0,1],[.9,.7,0,1],[0,.3,.7,1],[0,.7,0,1]]
for i in range(4):
btn = Button(id=btn_ids[i], size_hint=(.2, .2),
background_color=btn_colors[i],
background_normal='img/btn-normal.png',
background_down='img/btn-down.png',
pos_hint={'center_x': btn_pos[i][0], 'center_y': btn_pos[i][1]})
btn.bind(on_press=self.btn_press)
self.layout.add_widget(btn)
with self.canvas.before:
Color(1, 1, 1, 1)
self.rect = Rectangle(pos=self.pos, size=self.size, source='img/bpad.png')
self.bind(pos=self._update_rect)
self.bind(size=self._update_rect)
# self.polling = kw['polling'] if 'polling' in kw else .01
# Clock.schedule_interval(self.send_input, self.polling)
def _update_rect(self, *args):
self.rect.pos = self.pos
self.rect.size = self.size
self.layout.pos = self.pos
self.layout.size = self.size
def btn_press(self, btn):
self.notify('bpad_input', btn=btn.id)
def notify(self, event_name, *args, **kw):
for listener in self.listeners:
if event_name in listener.handlers:
getattr(listener, event_name)(*args, **kw)
# def send_input(self, dt):
# self.notify('bpad_input', input=self.input)