Kivy:你如何在 kivy 中制作一个圆形的 TextInput?
Kivy: How do you make a rounded TextInput in kivy?
好吧,伙计们,我已经研究过了,但是关于这个的一切都太少了。我只找到了这个:。所以伙计们,你们能告诉我们如何更容易地在 kivy 中制作一个圆形的文本输入吗?我需要一个解决方案。我试过 radius: [58]
,不行。我在上面的代码中听说过 link 中的椭圆,尽管我不确定如何使用它。它有什么作用 - 你如何使用它 - 或者它不是解决方案。
我不确定您所说的圆形文本输入是什么意思,但是使输入类似于椭圆的一种方法是使用 KivyMD。在 KivyMD 内部,有一个叫做 MDTextFieldRound 的东西可以给你这个。这里有一个页面:https://kivymd.readthedocs.io/en/0.104.1/components/text-field/
解决方法:复制粘贴此脚本并执行(记得把源码中的背景图片名称改成“a12.jpeg”),最后两张截图的输入好像变大了的原因这是因为对于 PC,分辨率必须更高,但在 phone 中,它将看起来是正常大小。
from kivymd.app import MDApp as jbsidis
from kivy.lang import Builder as jbsidisx
class jbsidis_Josue_Carranza(jbsidis):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def build(self):
return jbsidisx.load_string(M)
M="""
#:import Window kivy.core.window.Window
Screen:
bg_color: (1,1,1,.3)
highlight_color1jbsidis: [0,0,0,0]
highlight_color2jbsidis: (0,0,0,.3)
canvas.before:
Color:
rgba: [1,1,1,1]
Rectangle:
size: self.size
pos: self.pos
source: "a12.jpeg"
FloatLayout:
MDIconButton:
size_hint: .4, .05
pos_hint: {"center_x": .1, "top": .975}
text: "Back"
icon: 'chevron-left'
markup: True
TextInput:
id: email_jbsidis
hint_text_color: [0,0,0, 1]
foreground_color: [1,1,1,1]
hint_text: "Email"
background_color: [0,0,0,0]
background_image: ""
background_normal: ""
background_active: ""
multiline: False
size_hint: .7 ,.1 #.06
pos_hint: {'center_x':.5, 'center_y':.8} #'center_y':.8
canvas.before:
Color:
rgba: root.highlight_color2jbsidis if root.ids.email_jbsidis.focused else [1,1,1,.5]
RoundedRectangle:
size: self.size
pos: self.pos
radius: 10,
FloatLayout:
MDIconButton:
text: "[u]Reset password[/u]"
icon: 'email-send-outline'
markup: True
color: Window.clearcolor
opposite_colors: True
pos_hint: {'center_x':.8, 'center_y':.8}
TextInput:
id: password_jbsidis
hint_text: "Password"
foreground_color: [1,1,1,1]
background_color: [0,0,0,0]
background_image: ""
background_normal: ""
background_active: ""
multiline: False
password: True
size_hint: .7 ,.1 #.06
pos_hint: {'center_x':.5, 'center_y':.65}
canvas.before:
Color:
rgba: root.highlight_color2jbsidis if root.ids.password_jbsidis.focused else [1,1,1,.5]
RoundedRectangle:
size: self.size
pos: self.pos
radius: 10,
FloatLayout:
MDIconButton:
icon: 'lock-outline'
markup: True
color: Window.clearcolor
opposite_colors: True
pos_hint: {'center_x':.8, 'center_y':.65}
MDIconButton:
id: jbsidis_s
text: "[u]Reset password[/u]"
icon: 'lock-open-outline'
markup: True
color: Window.clearcolor
pos: password_jbsidis.pos[0]+password_jbsidis.size[0], password_jbsidis.pos[1]+dp(4)
pos_x: password_jbsidis.pos[0]
opposite_colors: True
MDRaisedButton:
id: jbsidis_i
text: "Sign In"
pos_hint: {"center_x": .5, "top": .5}
MDRaisedButton:
id: button_jbsidis
text: "Sign up"
size_hint: .2 ,.05
pos_hint: {"right": .85, "center_y": .1}
opacity: 0
disabled: True
bg_color: (0,0,0,1)
color: [0,0,0,1]
"""
jbsidis_Josue_Carranza().run()
图片:
好吧,伙计们,我已经研究过了,但是关于这个的一切都太少了。我只找到了这个:radius: [58]
,不行。我在上面的代码中听说过 link 中的椭圆,尽管我不确定如何使用它。它有什么作用 - 你如何使用它 - 或者它不是解决方案。
我不确定您所说的圆形文本输入是什么意思,但是使输入类似于椭圆的一种方法是使用 KivyMD。在 KivyMD 内部,有一个叫做 MDTextFieldRound 的东西可以给你这个。这里有一个页面:https://kivymd.readthedocs.io/en/0.104.1/components/text-field/
解决方法:复制粘贴此脚本并执行(记得把源码中的背景图片名称改成“a12.jpeg”),最后两张截图的输入好像变大了的原因这是因为对于 PC,分辨率必须更高,但在 phone 中,它将看起来是正常大小。
from kivymd.app import MDApp as jbsidis
from kivy.lang import Builder as jbsidisx
class jbsidis_Josue_Carranza(jbsidis):
def __init__(self, **kwargs):
super().__init__(**kwargs)
def build(self):
return jbsidisx.load_string(M)
M="""
#:import Window kivy.core.window.Window
Screen:
bg_color: (1,1,1,.3)
highlight_color1jbsidis: [0,0,0,0]
highlight_color2jbsidis: (0,0,0,.3)
canvas.before:
Color:
rgba: [1,1,1,1]
Rectangle:
size: self.size
pos: self.pos
source: "a12.jpeg"
FloatLayout:
MDIconButton:
size_hint: .4, .05
pos_hint: {"center_x": .1, "top": .975}
text: "Back"
icon: 'chevron-left'
markup: True
TextInput:
id: email_jbsidis
hint_text_color: [0,0,0, 1]
foreground_color: [1,1,1,1]
hint_text: "Email"
background_color: [0,0,0,0]
background_image: ""
background_normal: ""
background_active: ""
multiline: False
size_hint: .7 ,.1 #.06
pos_hint: {'center_x':.5, 'center_y':.8} #'center_y':.8
canvas.before:
Color:
rgba: root.highlight_color2jbsidis if root.ids.email_jbsidis.focused else [1,1,1,.5]
RoundedRectangle:
size: self.size
pos: self.pos
radius: 10,
FloatLayout:
MDIconButton:
text: "[u]Reset password[/u]"
icon: 'email-send-outline'
markup: True
color: Window.clearcolor
opposite_colors: True
pos_hint: {'center_x':.8, 'center_y':.8}
TextInput:
id: password_jbsidis
hint_text: "Password"
foreground_color: [1,1,1,1]
background_color: [0,0,0,0]
background_image: ""
background_normal: ""
background_active: ""
multiline: False
password: True
size_hint: .7 ,.1 #.06
pos_hint: {'center_x':.5, 'center_y':.65}
canvas.before:
Color:
rgba: root.highlight_color2jbsidis if root.ids.password_jbsidis.focused else [1,1,1,.5]
RoundedRectangle:
size: self.size
pos: self.pos
radius: 10,
FloatLayout:
MDIconButton:
icon: 'lock-outline'
markup: True
color: Window.clearcolor
opposite_colors: True
pos_hint: {'center_x':.8, 'center_y':.65}
MDIconButton:
id: jbsidis_s
text: "[u]Reset password[/u]"
icon: 'lock-open-outline'
markup: True
color: Window.clearcolor
pos: password_jbsidis.pos[0]+password_jbsidis.size[0], password_jbsidis.pos[1]+dp(4)
pos_x: password_jbsidis.pos[0]
opposite_colors: True
MDRaisedButton:
id: jbsidis_i
text: "Sign In"
pos_hint: {"center_x": .5, "top": .5}
MDRaisedButton:
id: button_jbsidis
text: "Sign up"
size_hint: .2 ,.05
pos_hint: {"right": .85, "center_y": .1}
opacity: 0
disabled: True
bg_color: (0,0,0,1)
color: [0,0,0,1]
"""
jbsidis_Josue_Carranza().run()
图片: