瀏覽代碼

feat: add `style()` method to `Output`

wangweimin 4 年之前
父節點
當前提交
b5b96f0c8f
共有 1 個文件被更改,包括 17 次插入0 次删除
  1. 17 0
      pywebio/io_ctrl.py

+ 17 - 0
pywebio/io_ctrl.py

@@ -125,6 +125,23 @@ class Output:
 
     show = send  # `show` is a more user-friendly name
 
+    def style(self, css_style):
+        """Set css style for output
+
+        Example::
+
+            put_text('hello').style('color: red; font-size: 20px')
+
+            put_row([
+                put_text('hello').style('color: red'),
+                put_markdown('markdown')
+            ]).style('margin-top: 20px')
+
+        """
+        self.spec.setdefault('style', '')
+        self.spec['style'] += ';%s' % css_style
+        return self
+
     def __del__(self):
         """返回值没有被变量接收时的操作:直接输出消息"""
         if not self.processed: