from remi.server import App, start import remi.gui as gui # 基本控件 label、test_input、drop_down、button、table_list class FirstApp(App): def __init__(self, *args): super(FirstApp, self).__init__(*args) def main(self): window = gui.VBox(width='100%', height='100%') # 全屏 self.label = gui.Label('Hello World', width='90%', height='5%') # 控件: label self.text_input = gui.TextInput(hint='Your Input') # 控件: text_input self.drop_down = gui.DropDown(width='90%', height='5%') # 控件: drop_down self.drop_down.append(gui.DropDownItem(text="item_one"), "item1") self.drop_down.append(gui.DropDownItem(text="item_two"), "item2") self.drop_down.style.update({'font-size': 'small'}) self.button = gui.Button(text='Press Me=点击我!', width='90%', height='5%') # 控件: button self.button.onclick.do(callback=self._on_button_pressed) # button 绑定方法 myList = [('ID', 'Lastname', 'Firstname', '邮编', '城市'), ('1', 'Pan', 'Peter', '888888', '上海'), ('2', 'Sepp', 'Schmuck', '123456', '北京')] self.table = gui.Table.new_from_list(content=myList, width='90%', fill_title=True) # fill_title: True代表第一行是蓝色, False代表表格内容全部同色 return self._add_subviews(self.drop_down, self.label, self.table, self.text_input, self.button, window=window) # private part def _on_button_pressed(self, emitter): self.label.set_text(text="My Python") @staticmethod def _add_subviews(*subviews, window): [window.append(subview) for subview in subviews] return window # 控件 tab_box 的 三种 响应方式 class SecondApp(App): def __init__(self, *args): super(SecondApp, self).__init__(*args) def main(self): window = gui.VBox(width='100%', height='100%') first_button = gui.Button(text="first_button", width=200, height=30) second_button = gui.Button(text="second_button", width=200, height=30) third_button = gui.Button(text="third_button", width=200, height=30) # 表格框 tab_box = gui.TabBox(width='90%') tab_box.add_tab(widget=first_button, key="first button") tab_box.add_tab(widget=second_button, key="second button") tab_box.add_tab(widget=third_button, key="third button") # tab_box控件 的 三种 响应方式 first_button.onclick.do(callback=self._tab_first_button_click, tabbox=tab_box, refWidgetTab=second_button) second_button.onclick.do(callback=self._tab_second_button_click, tabbox=tab_box, refWidgetTabName="third button") third_button.onclick.do(callback=self._tab_third_button_click, tabbox=tab_box, tabIndex=0) return self._add_subviews(tab_box, first_button, window=window) # private part @staticmethod def _add_subviews(*subviews, window): [window.append(subview) for subview in subviews] return window @staticmethod def _tab_first_button_click(widget, tabbox, refWidgetTab): tabbox.select_by_widget(refWidgetTab) @staticmethod def _tab_second_button_click(widget, tabbox, refWidgetTabName): tabbox.select_by_name(refWidgetTabName) @staticmethod def _tab_third_button_click(widget, tabbox, tabIndex): tabbox.select_by_index(tabIndex) # 控件 drop_down 的 响应方法 class ThirdApp(App): def __init__(self, *args, **kwargs): super(ThirdApp, self).__init__(*args, **kwargs) def main(self): window = gui.VBox(width='100%', height='100%') drop_down = gui.DropDown(width='50%', height='5%') # 控件: drop_down drop_down.append(gui.DropDownItem(text="item_one"), "item1") drop_down.append(gui.DropDownItem(text="item_two"), "item2") drop_down.append(gui.DropDownItem(text="item_three"), "item3") drop_down.append(gui.DropDownItem(text="item_four"), "item4") drop_down.style.update({'font-size': 'small'}) drop_down.onchange.do(callback=self._drop_down_change) return self._add_subviews(drop_down, window=window) @staticmethod def _add_subviews(*subviews, window): [window.append(subview) for subview in subviews] return window @staticmethod def _drop_down_change(widget, selected_item): print("_drop_down_change: widget={widget} select_item={selected_item}".format(widget=widget, selected_item=selected_item)) print(widget.get_value()) print(widget.get_key()) print(widget.get_item()) if __name__ == '__main__': start(main_gui_class=ThirdApp, standalone=True)
量化交易之python篇 - remi库 - 基础控件和响应方法
最新推荐文章于 2024-01-22 19:54:00 发布