python - 使 Kivy TextInput Frames 不可见但显示文本

标签 python kivy textinput

我正在尝试通过使用

使 TextInput 小部件像您一样“不可见”
opacity: 0

但是,我希望显示 TextInput 中的文本。如果我使用

opacity: 0

TextInput 小部件和小部件内的文本不可见,有没有办法在显示文本的同时“隐藏”小部件?

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen


class ExampleScreen(Screen):
    pass


class ExampleManager(ScreenManager):
    pass


root_widget = Builder.load_string('''
ExampleManager:
    ExampleScreen:

<ExampleScreen>:
    name: 'example_screen'
    TextInput:
        id: t_1
        text: 'Test text in input 1'
        size_hint: .5, .5
        pos_hint: {'x': 0, 'y': .5}
        multiline: True
        readonly: True
        opacity: 0  ## If I remove this line both text edits are visible. 
                    ##You can test this by putting ## before opacity

        ## What I'm trying to do, is make the TextInput widget opaque so 
        ##that you can't see the frame and only the text is visible

    TextInput:
        id: t_2
        text: 'Test text in input 2'
        size_hint: .5, .5
        pos_hint: {'x': 0, 'y': 0}
        multiline: True
        readonly: True
        opacity: 0  ## If I remove this line both text edits are visible. 
                    ##You can test this by putting ## before opacity

        ## What I'm trying to do, is make the TextInput widget opaque so 
        ##that you can't see the frame and only the text is visible

''')

class TestWidgetsApp(App):
    def build(self):
        self.title = 'Proj'
        return root_widget

TestWidgetsApp().run()

最佳答案

使用background_color属性并将 alpha channel 设置为 0:

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen


class ExampleScreen(Screen):
    pass


class ExampleManager(ScreenManager):
    pass


root_widget = Builder.load_string('''
ExampleManager:
    ExampleScreen:

<ExampleScreen>:
    name: 'example_screen'
    TextInput:
        id: t_1
        text: 'Test text in input 1'
        size_hint: .5, .5
        pos_hint: {'x': 0, 'y': .5}
        multiline: True
        readonly: True
        foreground_color: (1,0,1,1)
        background_color: (0,0,0,0)

    TextInput:
        id: t_2
        text: 'Test text in input 2'
        size_hint: .5, .5
        pos_hint: {'x': 0, 'y': 0}
        multiline: True
        readonly: True
        foreground_color: (1,1,0,1)
        background_color: (0,0,0,0)

''')

class TestWidgetsApp(App):
    def build(self):
        self.title = 'Proj'
        return root_widget

TestWidgetsApp().run()

enter image description here

关于python - 使 Kivy TextInput Frames 不可见但显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47609965/

相关文章:

python - 如何从 Kivy 按钮启动线程?

javascript - 如何将文本转换为输入?

javascript - 输入字段中的背景问题

forms - 为什么 ColdFusion 认为值 "7+"是一个有效的整数值,我如何验证它不是?

Python 3.4 嵌套循环使用 lambda 过滤器工作异常

python - 尝试从 iPython 运行脚本时出现语法错误

python - 多个 kivy 下拉

python - 是否可以在 kivy GridLayout 中为特定的小部件指定特定的网格

python - Docker python 请求导致 DH KEY TOO SMALL 错误

python - 从 scipy.interpolate.InterpolatedUnivariateSpline 中捕获 dfitpack.error