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

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

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

""" Here is shown the usage of GridBox layout.
    The gridbox layouting allows a flexible way to define a layout matrix
     using GridBox.define_grid, passing as parameter a two dimensional iterable.
    Each element in the defined grid, is the "key" to address a widget by the 
    GridBox.append method.
    In this example, the matrix is a list of strings, where each character is used
     as a "key". A key can occur multiple times in the defined matrix, making the 
     widget to cover a bigger area.
    The size of each column and row in the grid can be defined by GridBox.style,
     and the style parameters are 
     {'grid-template-columns':'10% 90%', 'grid-template-rows':'10% 90%'}.
"""

import remi.gui as gui
from remi import start, App
import os


class MyApp(App):
    def main(self):
        #creating a container GridBox type
        main_container = gui.GridBox(width='100%', height='100%', style={'margin':'0px auto'})
        
        label = gui.Label('This is a label')
        label.style['background-color'] = 'lightgreen'
        
        button = gui.Button('Change layout', height='100%')
        button.onclick.do(self.redefine_grid, main_container)
        
        text = gui.TextInput()

        
        main_container.set_from_asciiart("""
            |label |button                      |
            |label |text                        |
            |label |text                        |
            |label |text                        |
            |label |text                        |
            """, 10, 10)

        main_container.append({'label':label, 'button':button, 'text':text})

        # returning the root widget
        return main_container
    
    def redefine_grid(self, emitter, container):
        #redefining grid layout
        container.define_grid([ ['text','label','button'],['text','.','.']])
        container.style.update({'grid-template-columns':'33% 33% 33%', 'grid-template-rows':'50% 50%'})
        container.set_column_gap("0%")
        container.set_row_gap("0%")
        emitter.set_text("Done")


if __name__ == "__main__":
    start(MyApp, debug=True)

执行效果:

很抱歉,作为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库并开始编自己的登录注册网页!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

YYDataV软件开发

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

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

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

打赏作者

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

抵扣说明:

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

余额充值