让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()
+0
我立即纠正,谢谢队友! – Afflicted
考虑设置你的ExampleScreen的背景颜色和你的TextInput的背景色设置为相同的颜色 –
如果你不想设置background_color,你可以选择将background_normal和background_active图像设置为'' –