让Kivy的TextInput框架看不见,但显示文字

我试图用让Kivy的TextInput框架看不见,但显示文字

opacity: 0 

然而,为了将TextInput控件“看不见”的,就像您,我想了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属性和设置阿尔法通道,以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的TextInput框架看不见,但显示文字 的全部内容, 来源链接: utcz.com/qa/257256.html

回到顶部