采用Remi纯Python写前端页面,范例29

来源:remi源码https://github.com/dddomodossola/remi

官网:https://remi.readthedocs.io/en/latest/

import remi.gui as gui
from remi import start, App
from remi_ext import TreeTable, SingleRowSelectionTable

class MyApp(App):
    def __init__(self, *args):
        super(MyApp, self).__init__(*args)

    def main(self):
        self.wid = gui.VBox(style={'margin':'5px auto', 'padding': '10px'})
        table = [('', '#ff9', 'cable', '1', '2', '3'),
                 ('cable', '#ff9', '1-core cable', '1', '2', '3'),
                 ('cable', '#ff9', 'multi core cable', '1', '2', '3'),
                 ('multi core cable', '#ff9', '2-core cable', '1', '2', '3'),
                 ('multi core cable', '#ff9', '3-core cable', '1', '2', '3'),
                 ('3-core cable', '#ff9', '3-core armoured cable', '1', '2', '3'),
                 ('cable', '#ff9', 'armoured cable', '1', '2', '3'),
                 ('armoured cable', '#ff9', '3-core armoured cable', '1', '2', '3')]
        heads_color = '#dfd'
        uoms_color = '#ffd'
        heads = ['heads', heads_color, 'object', 'one', 'two', 'three']
        uoms = ['uom', uoms_color, '', 'mm', 'cm', 'dm']
        self.My_TreeTable(table, heads, heads2=uoms)
        return self.wid

    def My_TreeTable(self, table, heads, heads2=None):
        ''' Define and display a table
            in which the values in first column form one or more trees.
        '''
        self.Define_TreeTable(heads, heads2)
        self.Display_TreeTable(table)

    def Define_TreeTable(self, heads, heads2=None):
        ''' Define a TreeTable with a heading row
            and optionally a second heading row.
        '''
        display_heads = []
        display_heads.append(tuple(heads[2:]))
        self.tree_table = TreeTable()
        self.tree_table.append_from_list(display_heads, fill_title=True)
        if heads2 is not None:
            heads2_color = heads2[1]
            row_widget = gui.TableRow()
            for index, field in enumerate(heads2[2:]):
                row_item = gui.TableItem(text=field,
                                         style={'background-color': heads2_color})
                row_widget.append(row_item, field)
            self.tree_table.append(row_widget, heads2[0])
        self.wid.append(self.tree_table)

    def Display_TreeTable(self, table):
        ''' Display a table in which the values in first column form one or more trees.
            The table has row with fields that are strings of identifiers/names.
            First convert each row into a row_widget and item_widgets
            that are displayed in a TableTree.
            Each input row shall start with a parent field (field[0])
            that determines the tree hierarchy but that is not displayed on that row.
            The parent widget becomes an attribute of the first child widget.
            Field[1] is the row color, field[2:] contains the row values.
            Top child(s) shall have a parent field value that is blank ('').
            The input table rows shall be in the correct sequence.
        '''
        parent_names = []
        hierarchy = {}
        indent_level = 0
        widget_dict = {}  # key, value = name, widget
        for row in table:
            parent_name = row[0]
            row_color = row[1]
            child_name = row[2]
            row_widget = gui.TableRow(style={'background-color': row_color})
            # Determine whether hierarchy of sub_sub concepts shall be open or not
            openness = 'true'
            row_widget.attributes['treeopen'] = openness
            # widget_dict[child_name] = row_widget
            for index, field in enumerate(row[2:]):
                # Determine field color
                field_color = '#ffff99'
                row_item = gui.TableItem(text=field,
                                         style={'text-align': 'left',
                                                'background-color': field_color})
                row_widget.append(row_item, field)
                if index == 0:
                    row_item.parent = parent_name
                    child_id = row_item

            # The root of each tree has a parent that is blank ('').
            # Each row with childs has as attribute openness, which by default is 'true'.
            # The fields can be given other attributes, such as color.

            # Verify whether the parent_name (child.parent)
            # is present or is in the list of parent_names.
            print('parent-child:', parent_name, child_name)
            if parent_name == '':
                hierarchy[child_name] = 0
                parent_names.append(child_name)
                target_level = 0
            elif parent_name in parent_names:
                hierarchy[child_name] = hierarchy[parent_name] + 1
                target_level = hierarchy[child_name]
            else:
                # Parent not in parent_names
                print('Error: Parent name "{}" does not appear in network'
                      .format(parent_name))
                return
            print('indent, target-pre:', indent_level, target_level,
                  parent_name, child_name)
            # Indentation
            if target_level > indent_level:
                self.tree_table.begin_fold()
                indent_level += 1
            if target_level < indent_level:
                while target_level < indent_level:
                    indent_level += -1
                    self.tree_table.end_fold()
            print('indent, target-post:', indent_level, target_level,
                  parent_name, child_name)
            if child_name not in parent_names:
                parent_names.append(child_name)
            self.tree_table.append(row_widget, child_name)


if __name__ == "__main__":
    # starts the webserver
    # optional parameters
    start(MyApp,address='127.0.0.1', port=8081, multiple_instance=False,
          enable_file_cache=True, update_interval=0.1, start_browser=True)
    # start(MyApp, debug=True, address='0.0.0.0', port=0 )

运行效果:

很抱歉,作为AI语言模型,我无法在本地环境中使用Remi库,因此无法为您提供完整的代码示例。但是,我可以为您提供Remi库的简介和一些代码片段,以帮助您开始编登录注册网页。 Remi是一个用于创建基于web的用户界面的Python库,它使用Python,允许您创建窗口、按钮、文本框等元素,并将它们组合成交互式用户界面。它还提供了一些预定义的组件,例如表格、图表和菜单栏。 下面是一些示例代码片段,可以帮助您开始编登录和注册页面: ```python import remi.gui as gui from remi import start, App class Login(App): def __init__(self, *args): super(Login, self).__init__(*args) # 创建登录表单元素 self.username = gui.TextInput(width=200, height=30) self.password = gui.TextInput(width=200, height=30, password=True) self.login_button = gui.Button('登录', width=200, height=30) # 将表单元素添加到界面 self.main_container = gui.VBox() self.main_container.append(gui.Label('用户名')) self.main_container.append(self.username) self.main_container.append(gui.Label('密码')) self.main_container.append(self.password) self.main_container.append(self.login_button) # 绑定按钮点击事件 self.login_button.onclick.do(self.login) # 设置界面 self.main_container.set_style({'margin': 'auto', 'padding': '50px', 'text-align': 'center'}) self.username.set_style({'margin': 'auto', 'text-align': 'center'}) self.password.set_style({'margin': 'auto', 'text-align': 'center'}) self.login_button.set_style({'margin': 'auto'}) # 显示界面 self.main_container.attributes['title'] = '登录' self.main_container.style['width'] = '300px' self.main_container.style['height'] = '200px' self.main_container.style['border'] = '1px solid #ccc' self.main_container.style['border-radius'] = '5px' self.main_container.style['background-color'] = '#f9f9f9' self.main_container.style['box-shadow'] = '0px 0px 10px 0px rgba(0,0,0,0.75)' self.main_container.style['-webkit-box-shadow'] = '0px 0px 10px 0px rgba(0,0,0,0.75)' self.main_container.style['-moz-box-shadow'] = '0px 0px 10px 0px rgba(0,0,0,0.75)' self.main_container.style['position'] = 'absolute' self.main_container.style['left'] = '50%' self.main_container.style['top'] = '50%' self.main_container.style['transform'] = 'translate(-50%, -50%)' self.main_container.style['z-index'] = '9999' self.main_container.style['font-family'] = 'Arial' self.main_container.style['font-size'] = '16px' self.main_container.style['color'] = '#333' self.main_container.style['overflow'] = 'hidden' self.main_container.style['display'] = 'none' self.append(self.main_container) def login(self, widget): # 处理登录逻辑 pass if __name__ == '__main__': start(Login) ``` 上面的代码创建了一个简单的登录表单,包括用户名、密码和登录按钮。它还定义了一个`login`方法,该方法将在用户单击登录按钮时调用。您需要在该方法中添加处理登录逻辑的代码。 类似地,您可以使用以下代码创建一个简单的注册表单: ```python class Register(App): def __init__(self, *args): super(Register, self).__init__(*args) # 创建注册表单元素 self.username = gui.TextInput(width=200, height=30) self.password = gui.TextInput(width=200, height=30, password=True) self.confirm_password = gui.TextInput(width=200, height=30, password=True) self.register_button = gui.Button('注册', width=200, height=30) # 将表单元素添加到界面 self.main_container = gui.VBox() self.main_container.append(gui.Label('用户名')) self.main_container.append(self.username) self.main_container.append(gui.Label('密码')) self.main_container.append(self.password) self.main_container.append(gui.Label('确认密码')) self.main_container.append(self.confirm_password) self.main_container.append(self.register_button) # 绑定按钮点击事件 self.register_button.onclick.do(self.register) # 设置界面 self.main_container.set_style({'margin': 'auto', 'padding': '50px', 'text-align': 'center'}) self.username.set_style({'margin': 'auto', 'text-align': 'center'}) self.password.set_style({'margin': 'auto', 'text-align': 'center'}) self.confirm_password.set_style({'margin': 'auto', 'text-align': 'center'}) self.register_button.set_style({'margin': 'auto'}) # 显示界面 self.main_container.attributes['title'] = '注册' self.main_container.style['width'] = '300px' self.main_container.style['height'] = '250px' self.main_container.style['border'] = '1px solid #ccc' self.main_container.style['border-radius'] = '5px' self.main_container.style['background-color'] = '#f9f9f9' self.main_container.style['box-shadow'] = '0px 0px 10px 0px rgba(0,0,0,0.75)' self.main_container.style['-webkit-box-shadow'] = '0px 0px 10px 0px rgba(0,0,0,0.75)' self.main_container.style['-moz-box-shadow'] = '0px 0px 10px 0px rgba(0,0,0,0.75)' self.main_container.style['position'] = 'absolute' self.main_container.style['left'] = '50%' self.main_container.style['top'] = '50%' self.main_container.style['transform'] = 'translate(-50%, -50%)' self.main_container.style['z-index'] = '9999' self.main_container.style['font-family'] = 'Arial' self.main_container.style['font-size'] = '16px' self.main_container.style['color'] = '#333' self.main_container.style['overflow'] = 'hidden' self.main_container.style['display'] = 'none' self.append(self.main_container) def register(self, widget): # 处理注册逻辑 pass if __name__ == '__main__': start(Register) ``` 这两个表单可以作为您的登录注册页面的基础,并且可以根据您的需要进行修改和扩展。希望这些示例代码可以帮助您入门Remi库并开始编自己的登录注册网页!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

YYDataV软件开发

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值