Pyform动态样式不需要

2024-05-26 19:54:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我昨天开始pyforms,看起来框架的许多部分还没有文档化。你知道吗

我编写了一个应用程序,需要根据需要更改样式。我坚持使用ControlButton.style而不是CSS文件。documentation没有提供如何使用style属性,因此我的尝试失败。它没有任何效果。你知道吗

pyforms style image

from pyforms.basewidget import BaseWidget
from pyforms.controls import ControlText
from pyforms.controls import ControlButton
import os


class GUI(BaseWidget):

    def __init__(self, *args, **kwargs):
        super().__init__('A test')

        self.set_margin(10)

        self._directory = ControlText('Directory')
        self._directory.value = 'C:\\'
        self._directory.changed_event = self.referesh_check
        self._ok  = ControlButton('OK')
        self._formset = [ ('_directory', ' ', '_ok') ]
        self.referesh_check()

    def referesh_check(self):
        dirpath = self._directory.value
        if os.path.exists(dirpath):
            print('found: ', dirpath)
            self._directory.style='color:green'
        else:
            print('not found: ', dirpath)
            self._directory.style='color:red'
            pass

if __name__ == '__main__':
    from pyforms import start_app
    start_app(GUI)


注意:

将样式用作方法失败,并出现错误

self._directory.style('background-color:green')

AttributeError: 'ControlText' object has no attribute 'style'


Tags: fromimportselfstylecheck样式directorycolor

热门问题