我们从Python开源项目中,提取了以下29个代码示例,用于说明如何使用kivy.uix.floatlayout.FloatLayout()。
def build(self): floater = FloatLayout() logo = Image(source='AutoPen.png', pos_hint={'center_x': 0.5, 'center_y': .6}) spiderman = Label( text='[size=24][i]With Great Power comes Great Responsibility[/i][/size]', markup=True, pos_hint={'center_x': 0.5, 'center_y': .2}) enter = Button(text='enter', size_hint=(0.2,0.1), pos_hint={'center_x': 0.5, 'center_y': .1}) floater.add_widget(logo) floater.add_widget(spiderman) floater.add_widget(enter) return floater
def build(self): self.title = 'Cedar Display Client' if self.config.get('window', 'fullscreen') == 'yes': Window.fullscreen = 'auto' if kivy.utils.platform is 'windows': self.icon = 'logo/logo-128x128.png' else: self.icon = 'logo/logo-1024x1024.png' self.source = DisplaySource(self, pos_hint = {'x': 1, 'y': 1}, size_hint = [None, None]) self.source.bind(on_touch_down = self.toggle_fullscreen) self.layout = FloatLayout() self.layout.add_widget(self.source) self.ui = UserInterface(self) return self.layout
def build(self): self.manager = ScreenManager() self.manager.transition = FadeTransition(duration=.25) self.game = Game() for screen in [TitleMenu(), NewGame(), LoadGame(), self.game]: self.manager.add_widget(screen) self.manager.current = 'TitleMenu' self.overlay = FloatLayout() self.overlay.add_widget(self.manager) return self.overlay # def on_start(self): # self.profile = cProfile.Profile() # self.profile.enable() # # def on_stop(self): # self.profile.disable() # self.profile.dump_stats('myapp.profile')
def read(self,*largs): content = FloatLayout() scroll = ScrollView() mdlist = MDList() content.add_widget(scroll) scroll.add_widget(mdlist) title = "Testimonies" pop = Popup(title= title,content= content,) pop.open() try: for message in Testify.select(): time.sleep(0.50) mdlist.add_widget(PopList(text=str(message.name),secondary_text=str(message.message))) print('reading testimonies') except peewee.OperationalError: self.login_failure('Check Network Connection') # mdlist.add_widget(PopList(text=str('Error'), secondary_text=str('Please Check Internet Connection')))
def _build_menu_and_reset(self): menu_and_reset_box = FloatLayout() menu_and_reset_box.add_widget(self._menu_layout()) menu_and_reset_box.add_widget(self._reset_layout()) return menu_and_reset_box
def __init__(self, screendef): try: from kivy.uix.floatlayout import FloatLayout kivy = True except: import ui kivy = False unipage.__init__(self, kivy, screendef[0]) self.setscreen() self.screendef = screendef
def build(self): mainpage = FloatLayout() logo = Image(source='AutoPen.png', pos_hint={'center_x': 0.5, 'center_y': .6}) spiderman = Label( text='[size=24][i]With Great Power comes Great Responsibility[/i][/size]', markup=True, pos_hint={'center_x': 0.5, 'center_y': .2}) enter = Button(text='enter', size_hint=(0.2,0.1), pos_hint={'center_x': 0.5, 'center_y': .1}) mainpage.add_widget(logo) mainpage.add_widget(spiderman) mainpage.add_widget(enter) return mainpage #layout.add_widget(MainToolsScreen())
def build(self): floater = FloatLayout() self.widget = Button(text='herpderp', pos = (200,200), size_hint=(0.2,0.2)) self.backbutton = Button(text='back', pos=(0,0), size_hint =(0.1,0.2)) self.widget.bind(on_press=self.animate) self.backbutton.bind(on_press=self.back) floater.add_widget(self.widget) floater.add_widget(self.backbutton) return floater
def build(self): floater = FloatLayout()
def setup_gui(self): # vytvá?í grafické rozhraní self.sm = ScreenManager(transition=SlideTransition(direction="left")) self.gameScreen = Screen(name='GameScreen') self.layout = FloatLayoutBG(size_hint=(1,1)) self.sOverlay = FloatLayout(size_hint=(1,1)) self.field = GameMatrix(self, cols=12, rows=22, size_hint=(0.75, 0.83), pos_hint={'center_x':0.5, 'center_y':0.5}, master=self.layout, spacing=1) self.id_label = Label(font_name='font/Roboto-Thin.ttf', text=u'', pos_hint={'top':1, 'right':0.125}, size_hint=(0.125,0.085), font_size='48dp') self.overlay = Overlay(self, size_hint=(.1,1), pos_hint={"right":1}) self.dock = Dock(self, size_hint=(0.75,0.0845), pos_hint={'center_x':0.5}, opacity=1) self.layout.add_widget(self.field, index=0) self.layout.add_widget(self.id_label, index=0) self.nicknameLabel = Label(font_name='font/Roboto-Regular.ttf', text=self.nickname, pos_hint={'top':1, 'center_x':0.5}, font_size='26dp', size_hint=(0.75,0.085)) self.nextPiece = NextPiece() self.layout.add_widget(self.nextPiece) self.layout.add_widget(self.nicknameLabel, index=0) self.layout.add_widget(self.dock, index=0) self.layout.add_widget(self.overlay) self.layout.add_widget(self.sOverlay) self.layout.add_widget(GestureListener(root=self, pos_hint={'x': 0})) self.chat = Notification() self.chat.unread.opacity = 0 self.layout.add_widget(self.chat) self.gameScreen.add_widget(self.layout) self.sm.add_widget(LanguageScreen(name='LanguageScreen', root=self)) self.sm.add_widget(MainMenuScreen(name='MainMenuScreen', root=self)) self.sm.add_widget(ConnectScreen(name='ConnectScreen', root=self)) self.sm.add_widget(self.gameScreen) self.sm.add_widget(PartylineScreen(name="PartylineScreen", root=self)) self.sm.add_widget(StatsScreen(name="StatsScreen", root=self)) self.sm.add_widget(SettingsScreen(name="SettingsScreen", root=self)) self.sm.add_widget(BookmarksScreen(name="BookmarksScreen", root=self)) self.sm.add_widget(TutorialMove(root=self, name="TutorialMove", directory="moving", frames=5)) self.sm.add_widget(TutorialDrop(root=self, name="TutorialDrop", directory="drop", frames=3)) self.sm.add_widget(TutorialSpecial(root=self, name="TutorialSpecial", directory="sendspecial", frames=4)) self.sm.add_widget(TutorialNavigate(root=self, name="TutorialNavigate", directory="navigation", frames=7)) self.sm.add_widget(TutorialPlayers(root=self, name="TutorialPlayers", directory="players", frames=4)) return self.sm
def build(self): main_widget = Builder.load_string(""" #:import MDRaisedButton kivymd.button.MDRaisedButton #:import MDThemePicker kivymd.theme_picker.MDThemePicker FloatLayout: MDRaisedButton: size_hint: None, None pos_hint: {'center_x': .5, 'center_y': .5} size: 3 * dp(48), dp(48) center_x: self.parent.center_x text: 'Open theme picker' on_release: MDThemePicker().open() opposite_colors: True """) return main_widget
def build(self): f = FloatLayout() s = Scatter() l = Label(text='Hello!', font_size=150) b = BoxLayout(orientation='vertical') t = TextInput(font_size=150) f.add_widget(s) s.add_widget(l) b.add_widget(f) b.add_widget(t) return b
def __init__(self): super().__init__() self.images = dict() self.root = FloatLayout(size=(Window.width, Window.height)) self.grid = GridLayout(cols=8) self.add_widget(self.root) self.root.add_widget(self.grid) for i, bucket in enumerate(config["visual_debugger"]["available_buckets"]): layout = BoxLayout(orientation="vertical") image = VisualDebuggerImage( allow_stretch=True ) image.bind(texture=image.update_texture_filters) self.images[bucket] = image layout.add_widget(image) label = Label( text=bucket, color=(1, 1, 1, 1), size_hint=(1, 0.1) ) layout.add_widget(label) self.grid.add_widget(layout) Window.bind(on_resize=self.on_window_resize) Window.clearcolor = (0.136, 0.191, 0.25, 1)
def __init__(self, **kwargs): super(WelcomeScreen, self).__init__(**kwargs) self.layout = FloatLayout() #Float Layout for positioning buttons and image anywhere on the screen self.layout.width = Window.width #the float layout is the size of the window self.layout.height = Window.height self.layout.x = Window.width/2 - self.layout.width/2 #sets the x position of the layout to 0 self.layout.y = Window.height/2 - self.layout.height/2 #sets the y position of the layout to 0 self.add_widget(self.layout) #adds the layout to the screen self.img = Image(source = self.welcomeImage) self.img.size = (Window.width*1.0, Window.height*1.2) self.img.pos = (-Window.width*0.0, -Window.height*0.0) self.img.opacity = 1.0 #alpha value between 0.0 - 1.0 self.add_widget(self.img) #adds the image to the screen tmpBtn1 = MyButton(text = self.buttonList[0]) #start button tmpBtn1.size_hint = (.21, .09) tmpBtn1.pos_hint ={'x': .395, 'y': .24} tmpBtn1.background_color = [.4, .4, .4, .4] #backgroundcolor of the button (this is grayish) tmpBtn1.bind(on_release = self.changer) #when the button is released the changer function is called self.layout.add_widget(tmpBtn1) #adds the button called tmpBtn1 to the floatlayout tmpBtn2 = MyButton(text = self.buttonList[1]) #about button tmpBtn2.size_hint = (.08, .095) tmpBtn2.pos_hint ={'x': .618, 'y': 0} tmpBtn2.background_color = [.4, .4, .4, .4] tmpBtn2.bind(on_release = self.about) #when the button is released the about function is called self.layout.add_widget(tmpBtn2) #adds the button called tmpBtn2 to the floatlayout tmpBtn3 = MyButton(text = self.buttonList[2]) #uiowa button tmpBtn3.size_hint = (.08, .095) tmpBtn3.pos_hint = {'x':.7, 'y': 0} tmpBtn3.background_color = [.4, .4, .4, .4] tmpBtn3.bind(on_release = self.uiowa) #when the button is released the uiowa function is called self.layout.add_widget(tmpBtn3) #adds the button called tmpBtn3 to the floatlayout
def __init__(self, **kwargs): super(AboutScreen, self).__init__(**kwargs) self.layout = FloatLayout() self.layout.width = Window.width self.layout.height = Window.height self.layout.x = Window.width/2 - self.layout.width/2 self.layout.y = Window.height/2 - self.layout.height/2 self.add_widget(self.layout) self.img = Image(source = self.aboutImage) self.img.size = (Window.width*1.0, Window.height*1.0) self.img.pos = (-Window.width*0.0, -Window.height*0.0) self.img.opacity = 0.4 self.add_widget(self.img) self.aboutText = Label(text= 'GravBox is the interface application for the Augmented Reality (AR) Sandbox for gravitational dynamics simulations designed and built\n by Dr. Hai Fu\'s Introduction to Astrophysics class during the 2016-2017 academic year and beyond.\n GravBox itself was designed by Zachary Luppen, Erin Maier, and Mason Reed.\n\nAR Sandbox is the result of an NSF-funded project on informal science education for freshwater lake and watershed science developed by the\n UC Davis\' W.M. Keck Center for Active Visualization in the Earth Sciences (KeckCAVES),\n together with the UC Davis Tahoe Environmental Research Center, Lawrence Hall of Science, and ECHO Lake Aquarium and Science Center.') self.aboutText.pos = (.5, .5) #self.aboutText.size = self.size self.add_widget(self.aboutText) tmpBtn1 = MyButton(text = 'BACK') #start button tmpBtn1.size_hint = (.1, .1) tmpBtn1.pos_hint ={'x': 0, 'y': .90} tmpBtn1.background_color = [.4, .4, .4, 1] tmpBtn1.bind(on_release = self.backButton) #when the button is released the callback function is called self.layout.add_widget(tmpBtn1)
def __init__(self, **kwargs): super(UiowaScreen, self).__init__(**kwargs) self.layout = FloatLayout() self.layout.width = Window.width self.layout.height = Window.height self.layout.x = Window.width/2 - self.layout.width/2 self.layout.y = Window.height/2 - self.layout.height/2 self.add_widget(self.layout) self.img = Image(source = self.uiowaImage) self.img.size = (Window.width*1.0, Window.height*1.0) self.img.pos = (-Window.width*0.0, -Window.height*0.0) self.img.opacity = 0.4 self.add_widget(self.img) self.aboutText = Label(text= 'UIOWA INFO HERE') self.aboutText.pos = (.25, .25) self.add_widget(self.aboutText) tmpBtn1 = MyButton(text = 'BACK') #start button tmpBtn1.size_hint = (.1, .1) tmpBtn1.pos_hint ={'x': 0, 'y': .9} tmpBtn1.background_color = [.4, .4, .4, 1] tmpBtn1.bind(on_release = self.backButton) #when the button is released the backButton function is called self.layout.add_widget(tmpBtn1)
def __init__(self, **kwargs): super(WelcomeScreen, self).__init__(**kwargs) layout = FloatLayout() #Float Layout for positioning buttons and image anywhere on the screen layout.width = Window.width #the float layout is the size of the window layout.height = Window.height layout.x = Window.width/2 - layout.width/2 #sets the x position of the layout to 0 layout.y = Window.height/2 - layout.height/2 #sets the y position of the layout to 0 self.add_widget(layout) #adds the layout to the screen img = Image(source = self.welcomeImage) #BACKGROUND IMAGE img.size = (Window.width*1.0, Window.height*1.0) img.pos = (-Window.width*0.0, -Window.height*0.0) img.opacity = 1.0 #alpha value between 0.0 - 1.0 self.add_widget(img) #adds the image to the screen startBtn = MyButton(text = '') #start button startBtn.size_hint = (.21, .09) startBtn.pos_hint ={'x': .395, 'y': .24} startBtn.background_color = [.4, .4, .4, .4] #backgroundcolor of the button (this is grayish) startBtn.bind(on_release = self.changer) #when the button is released the changer function is called self.add_widget(startBtn) #adds the button called startButton to the floatlayout aboutBtn = MyButton(text = '') #about button aboutBtn.size_hint = (.08, .095) aboutBtn.pos_hint ={'x': .618, 'y': 0} aboutBtn.background_color = [.4, .4, .4, .4] aboutBtn.bind(on_release = self.about) #when the button is released the about function is called self.add_widget(aboutBtn) #adds the button called aboutBtn to the floatlayout uiowaBtn = MyButton(text = '') #uiowa button uiowaBtn.size_hint = (.08, .095) uiowaBtn.pos_hint = {'x':.7, 'y': 0} uiowaBtn.background_color = [.4, .4, .4, .4] uiowaBtn.bind(on_release = self.uiowa) #when the button is released the uiowa function is called self.add_widget(uiowaBtn) #adds the button called uiowaBtn to the floatlayout
def __init__(self, **kwargs): super(AboutScreen, self).__init__(**kwargs) layout = FloatLayout() layout.width = Window.width layout.height = Window.height layout.x = Window.width/2 - layout.width/2 layout.y = Window.height/2 - layout.height/2 self.add_widget(layout) img = Image(source = self.aboutImage) img.size = (Window.width*1.0, Window.height*1.0) img.pos = (-Window.width*0.0, -Window.height*0.0) img.opacity = 0.4 self.add_widget(img) aboutText = Label(text= 'GravBox is the interface application for the Augmented Reality (AR) Sandbox for gravitational dynamics simulations designed and built\nby Dr. Hai Fu\'s Introduction to Astrophysics class during the 2016-2017 academic year and beyond.\nGravBox itself was designed by Zachary Luppen, Erin Maier, and Mason Reed.\n\nAR Sandbox is the result of an NSF-funded project on informal science education for freshwater lake and watershed science developed by the\nUC Davis\' W.M. Keck Center for Active Visualization in the Earth Sciences (KeckCAVES),\ntogether with the UC Davis Tahoe Environmental Research Center, Lawrence Hall of Science, and ECHO Lake Aquarium and Science Center.', halign='center', valign='center') aboutText.pos = (.25, .25) self.add_widget(aboutText) backBtn = MyButton(text = 'BACK') # back button backBtn.size_hint = (.1, .1) backBtn.pos_hint ={'x': 0, 'y': .90} backBtn.background_color = [.4, .4, .4, 1] backBtn.bind(on_release = self.backButton) #when the button is released the callback function is called self.add_widget(backBtn)
def __init__(self, **kwargs): super(WelcomeScreen, self).__init__(**kwargs) layout = FloatLayout() #Float Layout for positioning buttons and image anywhere on the screen layout.width = Window.width #the float layout is the size of the window layout.height = Window.height layout.x = Window.width/2 - layout.width/2 #sets the x position of the layout to 0 layout.y = Window.height/2 - layout.height/2 #sets the y position of the layout to 0 self.add_widget(layout) #adds the layout to the screen img = Image(source = self.welcomeImage) #BACKGROUND IMAGE img.size = (Window.width*1.0, Window.height*1.0) img.pos = (-Window.width*0.0, -Window.height*0.0) img.opacity = 1.0 #alpha value between 0.0 - 1.0 self.add_widget(img) #adds the image to the screen startBtn = MyButton(text = '') #start button startBtn.size_hint = (.21, .09) startBtn.pos_hint ={'x': .395, 'y': .24} startBtn.background_color = [.306, .325, .4196, .4] #backgroundcolor of the button (this is grayish) startBtn.bind(on_release = self.changer) #when the button is released the changer function is called self.add_widget(startBtn) #adds the button called startButton to the floatlayout aboutBtn = MyButton(text = '') #about button aboutBtn.size_hint = (.08, .095) aboutBtn.pos_hint ={'x': .618, 'y': 0} aboutBtn.background_color = [.4, .4, .4, .4] aboutBtn.bind(on_release = self.about) #when the button is released the about function is called self.add_widget(aboutBtn) #adds the button called aboutBtn to the floatlayout uiowaBtn = MyButton(text = '') #uiowa button uiowaBtn.size_hint = (.08, .095) uiowaBtn.pos_hint = {'x':.7, 'y': 0} uiowaBtn.background_color = [.4, .4, .4, .4] uiowaBtn.bind(on_release = self.uiowa) #when the button is released the uiowa function is called self.add_widget(uiowaBtn) #adds the button called uiowaBtn to the floatlayout
def __init__(self, **kwargs): super(UiowaScreen, self).__init__(**kwargs) self.layout = FloatLayout() self.layout.width = Window.width self.layout.height = Window.height self.layout.x = 0 self.layout.y = 0 self.add_widget(self.layout) img = Image(source = self.uiowaImage) img.size = (Window.width*1.0, Window.height*1.0) img.pos = (0, 0) img.opacity = .8 self.add_widget(img, 1) with self.layout.canvas: #sets canvas instructions for the rightlayout and draws a blue rect. filling the entire layout Color(1, 1, 1, .7) #WHITE Rectangle(pos=(.15 * self.layout.height, .30 * self.layout.height), size=(.45 * self.layout.width, .55 * self.layout.height)) qr = Image(source = self.qrCode) qr.size_hint = (.39, .39) qr.pos_hint = {'x': .56, 'y': .12} self.add_widget(qr) logo = Image(source=self.uiLogo) logo.size_hint = (.33, .33) logo.pos_hint = {'x': .59, 'y': .58} self.add_widget(logo) uiowaText = Label(text= 'The GravBox project is the result of the hard work of students of the University of Iowa\'s Physics and Astronomy Department. To learn more about physics and astronomy at the University of Iowa, and the research work being done in these areas, please scan the QR code to the right.', valign='middle', halign='center', font_size='24sp', text_size=(.4 * self.layout.width, None), color=(0,0,0,1)) uiowaText.pos_hint = {'x': -.18, 'y': .075} self.add_widget(uiowaText) backBtn = MyButton(text = 'BACK') # back button backBtn.size_hint = (.1, .1) backBtn.pos_hint ={'x': .27, 'y': .16} backBtn.background_color = [.4, .4, .4, 1] backBtn.bind(on_release = self.backButton) #when the button is released the callback function is called self.add_widget(backBtn)
def setscreen(self): if self.kivy: from kivy.config import Config Config.set('input', 'mouse', 'mouse,multitouch_on_demand') from kivy.uix.floatlayout import FloatLayout from kivy.core.window import Window from kivy.utils import platform as core_platform self.root = FloatLayout() if (self.xratio == 0) or (self.yratio == 0): if core_platform == 'android': self.screen_size = Window.size else: self.screen_size = (800, 600) self.xratio = self.screen_size[0] / 800.0 self.yratio = self.screen_size[1] / 600.0 if core_platform == 'android': Window.softinput_mode = 'pan' else: Window.size = self.screen_size else: import ui if (self.xratio == 0) or (self.yratio == 0): ss1 = ui.get_screen_size()[0] ss3 = ui.get_screen_size()[1] notoptimal = True while notoptimal: if ss1 % 8 == 0: notoptimal = False else: ss1 -= 1 ss1 = ss1 - 124 ss2 = (ss1 / 4) * 3 if ss2 > ss3: ss2 = ss3 - ss2 - ((ss3 - ss2) % 3) ss1 = (ss2 / 3) * 4 self.screen_size = (ss1, ss2) self.xratio = self.screen_size[0] / 800 self.yratio = self.screen_size[1] / 600 self.root = ui.View(frame=(0,0,self.screen_size[0], \ self.screen_size[1]))
def setscreen(self): if self.kivy: from kivy.config import Config Config.set('input', 'mouse', 'mouse,multitouch_on_demand') from kivy.uix.floatlayout import FloatLayout from kivy.core.window import Window from kivy.utils import platform as core_platform self.root = FloatLayout() if (self.xratio == 0) or (self.yratio == 0): if core_platform == 'android': self.screen_size = Window.size if self.screen_size[0] < self.screen_size[1]: x = self.screen_size[0] y = self.screen_size[0] / 4 * 3 self.screen_size = (x, y) else: self.screen_size = (800, 600) self.xratio = self.screen_size[0] / 800.0 self.yratio = self.screen_size[1] / 600.0 if core_platform == 'android': Window.softinput_mode = 'pan' else: Window.size = self.screen_size else: import ui if (self.xratio == 0) or (self.yratio == 0): ss1 = ui.get_screen_size()[0] ss3 = ui.get_screen_size()[1] notoptimal = True while notoptimal: if ss1 % 8 == 0: notoptimal = False else: ss1 -= 1 ss2 = (ss1 / 4) * 3 title_bar_height = int(ss3 / 600 * 50) if ss2 > ss3 - title_bar_height: ss2 = ss3 - title_bar_height notoptimal = True while notoptimal: if ss2 % 6 == 0: notoptimal = False else: ss2 -= 1 ss1 = (ss2 / 3) * 4 self.screen_size = (ss1, ss2) self.xratio = ss1 / 800 self.yratio = ss2 / 600 self.root = ui.View(frame=(0,0,self.screen_size[0], \ self.screen_size[1]))
def setscreen(self): if self.kivy: from kivy.config import Config Config.set('input', 'mouse', 'mouse,multitouch_on_demand') from kivy.uix.floatlayout import FloatLayout from kivy.core.window import Window from kivy.utils import platform as core_platform self.root = FloatLayout() if (self.xratio == 0) or (self.yratio == 0): if core_platform == 'android': self.screen_size = Window.size if self.screen_size[0] < self.screen_size[1]: x = self.screen_size[0] y = self.screen_size[0] / 4 * 3 self.screen_size = (x, y) else: self.screen_size = (800, 600) self.xratio = self.screen_size[0] / 800.0 self.yratio = self.screen_size[1] / 600.0 if core_platform == 'android': Window.softinput_mode = 'pan' else: Window.size = self.screen_size else: import ui if (self.xratio == 0) or (self.yratio == 0): ss1 = ui.get_screen_size()[0] ss3 = ui.get_screen_size()[1] notoptimal = True while notoptimal: if ss1 % 8 == 0: notoptimal = False else: ss1 -= 1 ss2 = (ss1 / 4) * 3 title_bar_height = int(ss3 / 600 * 90) if ss2 > ss3 - title_bar_height: ss2 = ss3 - title_bar_height notoptimal = True while notoptimal: if ss2 % 6 == 0: notoptimal = False else: ss2 -= 1 ss1 = (ss2 / 3) * 4 self.screen_size = (ss1, ss2) self.xratio = ss1 / 800 self.yratio = ss2 / 600 self.root = ui.View(frame=(0,0,self.screen_size[0], \ self.screen_size[1]))