Python 使Kivy TextInput框架不可见,但显示文本

Python 使Kivy TextInput框架不可见,但显示文本,python,kivy,textinput,Python,Kivy,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):

我正试图通过使用

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()
从kivy.app导入应用
从kivy.lang导入生成器
从kivy.uix.screenmanager导入screenmanager,屏幕
类示例屏幕(屏幕):
通过
类示例示例管理器(屏幕管理器):
通过
root\u widget=Builder.load\u字符串(“”)
示例经理:
示例屏幕:
:
名称:“示例_屏幕”
文本输入:
id:t_1
文本:“输入1中的测试文本”
大小提示:.5,.5
位置提示:{'x':0,'y':.5}
多行:正确
只读:正确
不透明度:0##如果删除此行,则两个文本编辑都可见。
##您可以通过将##放在不透明度之前来测试这一点
##我想做的是让TextInput小部件不透明
##你看不到框架,只有文本可见
文本输入:
id:t_2
文本:“输入2中的测试文本”
大小提示:.5,.5
位置提示:{'x':0,'y':0}
多行:正确
只读:正确
不透明度:0##如果删除此行,则两个文本编辑都可见。
##您可以通过将##放在不透明度之前来测试这一点
##我想做的是让TextInput小部件不透明
##你看不到框架,只有文本可见
''')
类TestWidgetsApp(应用程序):
def生成(自):
self.title='Proj'
返回root\u小部件
TestWidgetsApp().run()
使用属性并将alpha chanel设置为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()
从kivy.app导入应用
从kivy.lang导入生成器
从kivy.uix.screenmanager导入screenmanager,屏幕
类示例屏幕(屏幕):
通过
类示例示例管理器(屏幕管理器):
通过
root\u widget=Builder.load\u字符串(“”)
示例经理:
示例屏幕:
:
名称:“示例_屏幕”
文本输入:
id:t_1
文本:“输入1中的测试文本”
大小提示:.5,.5
位置提示:{'x':0,'y':.5}
多行:正确
只读:正确
前景色:(1,0,1,1)
背景颜色:(0,0,0,0)
文本输入:
id:t_2
文本:“输入2中的测试文本”
大小提示:.5,.5
位置提示:{'x':0,'y':0}
多行:正确
只读:正确
前景色:(1,1,0,1)
背景颜色:(0,0,0,0)
''')
类TestWidgetsApp(应用程序):
def生成(自):
self.title='Proj'
返回root\u小部件
TestWidgetsApp().run()

考虑设置示例屏幕的背景色,并将文本输入的背景色设置为相同的颜色如果不想设置背景色,可以将背景正常和背景活动图像设置为“”