我们从Python开源项目中,提取了以下20个代码示例,用于说明如何使用kivy.uix.widget.Widget()。
def __init__(self, **kvargs): super(SelectColor, self).__init__(**kvargs) box = BoxLayout(orientation="vertical") select_color = ColorPicker(hex_color=self.default_color) button_select = Button(text=self.text_button_ok, size_hint=(1, .1)) box.add_widget(select_color) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(SettingSpacer()) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(button_select) self.body = Popup(title=self.title, content=box, size_hint=self.size, background=self.background_image) self.body.bind(on_dismiss=self.dismiss_callback) button_select.bind(on_press=lambda color: self.select_callback( select_color.hex_color), on_release=lambda *args: self.body.dismiss()) self.body.open()
def update(self, dt): self.mcnay.update() self.background.update() # Loop through and update obstacles. Replace obstacles which went off the screen. for obstacle in self.obstacles: obstacle.update() if obstacle.x < self.mcnay.x and not obstacle.marked: obstacle.marked = True self.score += 1 self.new_obstacle(remove=False) if len(self.obstacles) == 0: self.new_obstacle(remove=False) elif self.obstacles[0].x < 0: self.remove_obstacle() # If obstacles is emply # See if the player collides with any obstacles for obstacle in self.obstacles: if self.mcnay.collide_widget(Widget(pos=(obstacle.x, obstacle.gap_top + 20), size=(obstacle.width, obstacle.height - obstacle.gap_top))): # This will be replaced later on sys.exit() if self.mcnay.collide_widget(Widget(pos=(obstacle.x, 0), size=(obstacle.width, obstacle.gap_top - obstacle.gap_size))): # This will also be replaced sys.exit()
def __init__(self, **kvargs): super(CDialog, self).__init__(**kvargs) box = BoxLayout(orientation='vertical') select_color = ColorPicker(hex_color=self.default_color) button_select = Button( text=self.text_button_ok, size_hint=(1, .1), background_normal=self.background_image_buttons[0], background_down=self.background_image_shadows[0] ) box.add_widget(select_color) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(SettingSpacer()) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(button_select) button_select.bind( on_press=lambda color: self.events_callback(select_color.hex_color), on_release=lambda *args: self.dismiss() ) self.content = box self.open()
def __init__(self, **kvargs): super(CDialog, self).__init__(**kvargs) box = BoxLayout(orientation='vertical') select_color = ColorPicker(hex_color=self.default_color) button_select = Button( text=self.text_button_ok, size_hint=(1, .1), background_normal=self.background_image_buttons[0], background_down=self.background_image_shadows[0], background_color=choice(self.background_color_buttons) ) box.add_widget(select_color) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(SettingSpacer()) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(button_select) button_select.bind( on_press=lambda color: self.events_callback(select_color.hex_color), on_release=lambda *args: self.dismiss() ) self.content = box self.open()
def __init__(self, **kvargs): super(ProgressLoad, self).__init__(**kvargs) self.orientation = "vertical" self.padding = 20 self.KProgress = kvargs.get("KProgress") self.label_one = Label(text="", size_hint=(1, .1), markup=True) self.label_two = Label(text="", size_hint=(1, .1), markup=True) self.progress_load = self.KProgress() self.button_cancel = \ Button(text="Cancel", on_press=self.events_callback, size_hint=(1, .2)) self.label_one.bind( size=lambda *args: self._update_text_size(args)) self.label_two.bind( size=lambda *args: self._update_text_size(args)) self.add_widget(self.label_one) self.add_widget(self.label_two) self.add_widget(Widget(size_hint=(None, .02))) self.add_widget(SettingSpacer()) self.add_widget(Widget(size_hint=(None, .02))) self.add_widget(self.progress_load) self.add_widget(Widget(size_hint=(None, .3))) self.add_widget(SettingSpacer()) self.add_widget(Widget(size_hint=(None, .02))) self.add_widget(self.button_cancel) self.progress_load.min = 0 self.progress_load.max = 100 self.progress_load.bar_value = 0 self.progress_load.spacing_widget = 2 self.progress_load.height_widget = 1 self.progress_load.color = "#ff7f32" self.progress_load.background_color = "#2fbfe0" self.progress_load.border_color = "#2fbfe0"
def show_image(self, interval): """??????? ?? ????? ??????????? ???????????.""" if not self.flag: return image = Image(source=self.full_path_to_load_content) button = None for name_button in [self.text_button_ok, self.text_button_no, self.text_button_cancel]: if name_button: button = self.create_button(name_button) if not button: self.create_button("Yes") self.add_widget(image) self.add_widget(Widget(size_hint=(None, .03))) self.add_widget(SettingSpacer()) self.add_widget(Widget(size_hint=(None, .03))) self.add_widget(self.box_buttons_select) self.body.content = self self.body.open() Clock.unschedule(self.show_image)
def remove_widget(self, widget): if widget is self.side_panel: self._side_panel.remove_widget(widget) self.side_panel = None elif widget is self.main_panel: self._main_panel.remove_widget(widget) self.main_panel = None else: raise NavigationDrawerException( 'Widget is neither the side or main panel, can\'t remove it.')
def __init__(self, **kvargs): super(PDialog, self).__init__(**kvargs) self.box = BoxLayout(orientation='vertical') self.label_one = Label(text='', size_hint=(1, .1), markup=True) self.label_two = Label(text='', size_hint=(1, .1), markup=True) self.progress_load = Progress() self.button_cancel = Button( text='Cancel', on_press=self.events_callback, size_hint=(1, .1), background_normal=self.background_image_buttons[0], background_down=self.background_image_shadows[0] ) self.label_one.bind(size=lambda *args: self._update_text_size(args)) self.label_two.bind(size=lambda *args: self._update_text_size(args)) self.box.add_widget(self.label_one) self.box.add_widget(self.label_two) self.box.add_widget(Widget(size_hint=(None, .02))) self.box.add_widget(SettingSpacer()) self.box.add_widget(Widget(size_hint=(None, .02))) self.box.add_widget(self.progress_load) self.box.add_widget(Widget(size_hint=(None, .3))) self.box.add_widget(SettingSpacer()) self.box.add_widget(Widget(size_hint=(None, .02))) self.box.add_widget(self.button_cancel) self.progress_load.min = 0 self.progress_load.max = 100 self.progress_load.bar_value = 0 self.progress_load.height_widget = self.dp(self.progress_line_height) self.progress_load.color = self.progress_line_color self.progress_load.border_color = self.progress_border_color
def _get_form(self): layout = BoxLayout(orientation='vertical', spacing=5) text_input = TextInput(id='text', multiline=False, text=self.text, on_text_validate=self._on_text_validate, # DON`T UNCOMMENT OR FOUND AND FIX THE ISSUE # if `focus` set to `True` - TextInput will be # inactive to edit # focus=True, size_hint_y=None, height=metrics.dp(33)) layout.add_widget(Widget()) layout.add_widget(text_input) layout.add_widget(Widget()) return layout
def _get_form(self): layout = BoxLayout(orientation='vertical', spacing=5) layout.add_widget(Widget()) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Factory.XLabel(text=_('Login:'), halign='right', size_hint_x=None, width=metrics.dp(80))) pnl.add_widget(TextInput(id='login', multiline=False, font_size=metrics.sp(14), text=self.login)) layout.add_widget(pnl) pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget( Factory.XLabel(text=_('Password:'), halign='right', size_hint_x=None, width=metrics.dp(80))) pnl.add_widget(TextInput(id='password', multiline=False, font_size=14, password=True, text=self.password)) layout.add_widget(pnl) if self.autologin is not None: pnl = BoxLayout(size_hint_y=None, height=metrics.dp(28), spacing=5) pnl.add_widget(CheckBox( id='autologin', size_hint_x=None, width=metrics.dp(80), active=self.autologin)) pnl.add_widget( Factory.XLabel(text=_('Login automatically'), halign='left')) layout.add_widget(pnl) layout.add_widget(Widget()) return layout
def __init__(self, **kvargs): super(PDialog, self).__init__(**kvargs) self.box = BoxLayout(orientation='vertical') self.label_one = Label(text='', size_hint=(1, .1), markup=True) self.label_two = Label(text='', size_hint=(1, .1), markup=True) self.progress_load = Progress() self.button_cancel = Button( text='Cancel', on_press=self.events_callback, size_hint=(1, .1), background_normal=self.background_image_buttons[0], background_down=self.background_image_shadows[0], background_color=choice(self.background_color_buttons) ) self.label_one.bind(size=lambda *args: self._update_text_size(args)) self.label_two.bind(size=lambda *args: self._update_text_size(args)) self.box.add_widget(self.label_one) self.box.add_widget(self.label_two) self.box.add_widget(Widget(size_hint=(None, .02))) self.box.add_widget(SettingSpacer()) self.box.add_widget(Widget(size_hint=(None, .02))) self.box.add_widget(self.progress_load) self.box.add_widget(Widget(size_hint=(None, .3))) self.box.add_widget(SettingSpacer()) self.box.add_widget(Widget(size_hint=(None, .02))) self.box.add_widget(self.button_cancel) self.progress_load.min = 0 self.progress_load.max = 100 self.progress_load.bar_value = 0 self.progress_load.height_widget = self.dp(self.progress_line_height) self.progress_load.color = self.progress_line_color self.progress_load.border_color = self.progress_border_color
def show_orientation_arrow(self): # Create an arrow if it doesn't exist if type(self.mapviewer.arrow) != 'Widget': self.mapviewer.set_orientation_arrow(OrientationArrow()) if self.mapviewer.arrow not in self.children: self.add_widget(self.mapviewer.arrow) # Set the position to the former position self.mapviewer.set_arrow_pos()
def build(self): root = Widget() b1 = Button(pos=(0, 0), # background_color=(226, 13, 13, 1), size=(100, 50), text="Click Me") root.add_widget(b1) return root
def __init__(self, **kvargs): super(ProgressLoad, self).__init__(**kvargs) box = BoxLayout(orientation="vertical", padding=20) self.label_already_loaded = Label( text="", size_hint=(1, .1), markup=True) self.label_total_size = Label( text="", size_hint=(1, .1), markup=True) self.progress_load = KProgress() self.button_cancel = \ Button(text=self.text_button_cancel, on_press=self.events_callback, background_normal=self.button_cancel_background_normal, background_down=self.button_cancel_background_down, size_hint=(1, .2)) self.label_already_loaded.bind( size=lambda *args: self._update_text_size(args)) self.label_total_size.bind( size=lambda *args: self._update_text_size(args)) box.add_widget(self.label_already_loaded) box.add_widget(self.label_total_size) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(SettingSpacer()) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(self.progress_load) box.add_widget(Widget(size_hint=(None, .3))) box.add_widget(SettingSpacer()) box.add_widget(Widget(size_hint=(None, .02))) box.add_widget(self.button_cancel) self.progress_load.min = 0 self.progress_load.max = 100 self.progress_load.bar_value = 0 self.progress_load.spacing_widget = 2 self.progress_load.height_widget = 1 self.progress_load.color = self.progress_line_color self.progress_load.background_color = self.progress_background_color self.progress_load.border_color = self.progress_border_color self.body = Popup(title=self.title, content=box, auto_dismiss=False, size_hint=self.size_hint)
def __init__(self, **kvargs): super(ThemesForum, self).__init__(**kvargs) self.size_hint = (1, 1) box_scroll = ScrollView() box_scroll_and_paginator = BoxLayout(orientation="vertical", spacing=5) box_for_paginator = BoxLayout(size_hint_y=None, height=40) layout = GridLayout(cols=1, spacing=17, size_hint=(1, None)) layout.bind(minimum_height=layout.setter('height')) layout.add_widget(Widget(size_hint=(1, .5))) layout.add_widget(Label(text=self.title, font_size=self.font_size + 4, markup=True)) layout.add_widget(Widget(size_hint=(1, .5))) layout.add_widget(SettingSpacer()) # ????????? ???????. if self.flag != "forumcat": number_page = Label(text=self.number_page, markup=True) number_page.bind(on_ref_press=self.refs_callback) box_for_paginator.add_widget(number_page) for data in self.data: for key in ["theme", "total_topics", "last_theme", "sep", "last_answer"]: try: if data[key] == "": continue except KeyError: pass font_size = self.font_size + 4 if key == "theme" \ else self.font_size if key == "sep": layout.add_widget(Widget(size_hint=(1, .5))) else: name_item = data[key] info = Label(text=name_item, font_size=font_size, id=name_item, markup=True) info.bind( size=lambda *args: self._update_window_size(args), on_ref_press=self.refs_callback) layout.add_widget(info) if key == "theme": layout.add_widget(SettingSpacer()) layout.add_widget(SettingSpacer()) box_scroll.add_widget(layout) box_scroll_and_paginator.add_widget(box_scroll) if self.flag != "forumcat": box_scroll_and_paginator.add_widget(box_for_paginator) self.add_widget(box_scroll_and_paginator)
def build(self): root_widget = BoxLayout(orientation='vertical') drawing_widget = DrawingWidget() red_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=80) green_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=80) blue_slider = Slider(min=0, max=1, value=0.5, size_hint_y=None, height=80) colour_row = BoxLayout(orientation='horizontal', size_hint_y=None, height=80) colour_label = Label(text='output colour:') colour_widget = Widget() # We draw a Rectangle on colour_widget exactly the same way as # with DrawingWidget, just without making a new class with colour_widget.canvas: output_colour = Color(red_slider.value, green_slider.value, blue_slider.value) output_rectangle = Rectangle() def update_colour_widget_rect(instance, value): output_rectangle.pos = colour_widget.pos output_rectangle.size = colour_widget.size colour_widget.bind(pos=update_colour_widget_rect, size=update_colour_widget_rect) def update_colour_widget_colour(instance, value): output_colour.rgb = (red_slider.value, green_slider.value, blue_slider.value) red_slider.bind(value=update_colour_widget_colour) green_slider.bind(value=update_colour_widget_colour) blue_slider.bind(value=update_colour_widget_colour) root_widget.add_widget(drawing_widget) root_widget.add_widget(red_slider) root_widget.add_widget(green_slider) root_widget.add_widget(blue_slider) root_widget.add_widget(colour_row) colour_row.add_widget(colour_label) colour_row.add_widget(colour_widget) return root_widget
def draw_memory_state(self, mem_box, size_box, start_height, temp_memory, *args): # Unpack memory state details memory_state = temp_memory['memory_state'] # wait_queue = temp_memory['processes_waiting'] event_details = temp_memory['event'] process_id,arrival_bit,curr_time,burst_time,process_size = event_details chart_wid = Widget() # Increment in width per unit size self.inc = Window.width/(int(data_mem['mem_size'])*1.5) # Add description labels label = Label(text='Memory state: ', size_hint_x=None, width=self.margin_left) mem_box.add_widget(label) s_label = Label(text='Size: ', size_hint_x=None, width=self.margin_left, valign='top', halign='center') s_label.text_size = s_label.size size_box.add_widget(s_label) # Draw the memory state rectangles and add size labels if not memory_state: self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', 0, data_mem['mem_size']) else: for i,memory_slot in enumerate(memory_state): process_id1, start1, end1 = memory_slot if(len(memory_state) == 1): # only tuple in list if(start1 > 0): self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', 0, start1) self.add_process(chart_wid, mem_box, size_box, start_height, process_id1, start1, (end1-start1)) if(data_mem['mem_size']-end1 > 0): self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', end1, (data_mem['mem_size']-end1)) elif(i == len(memory_state)-1): #last tuple, more tuples preceded self.add_process(chart_wid, mem_box, size_box, start_height, process_id1, start1, (end1-start1)) if(data_mem['mem_size']-end1 > 0): self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', end1, (data_mem['mem_size']-end1)) else: process_id2,start2,end2 = memory_state[i+1] if(i == 0): # first tuple, more tuples follow if(start1 > 0): self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', 0, start1) self.add_process(chart_wid, mem_box, size_box, start_height, process_id1, start1, (end1-start1)) if(start2-end1 > 0): self.add_process(chart_wid, mem_box, size_box, start_height, 'hole', end1, (start2-end1)) # Add size label for the end of memory s_label = Label(text=str(data_mem['mem_size']), size_hint_x=None, width=self.inc*(data_mem['mem_size']), halign='left', valign='top') s_label.text_size = s_label.size size_box.add_widget(s_label) # Add the widget used to draw the meomory state on the screen mem_box.add_widget(chart_wid) # Drawing the wait queue