我想对按钮中的文本使用 unicode 符号,但 kivy 不想显示它。
像这样:
self.add_widget(KeyboardButtonOthers(text = u'\u232B', size_hint = (1/7, 0.2)))
#Here I use Sans font
或者这个:
<MainButton@Button>:
text: '⌂ Exit'
#Here I use default Roboto kivy font
在这两种情况下都不起作用。相反,我得到的是普通符号: Sans font
还有这个: Roboto font
我在 Windows 下工作,但我计划在 Linux 上安装该项目。也许他们可以在 Linux 上工作,而这是 Windows 的问题? 感谢您的帮助。
##########################
我在不使用 unicode 符号的情况下找到了一个很好的解决方案。如果您需要这样的东西,您可以尝试以下操作:
Builder.load_string("""
<KeyboardButtonBackspace@Button>:
background_color: (0, 0, 0, 0)
canvas.before:
Color:
rgba: (166/255, 166/255, 166/255, 1) if self.state == 'normal' else (80/255, 80/255, 80/255, 1)
RoundedRectangle:
pos: self.pos
size: self.size
radius: [5]
Image:
source: 'images/clear2.png'
size: self.parent.size
y: self.parent.y
x: self.parent.x
allow_stretch: True
""")
Clear2 是来自此处的矢量图标 https://icons8.com/icons/set/clear
最佳答案
使用的字体可能不包含 U+232B ERASE TO THE LEFT 的字形Unicode 代码点 - 因此使用失败/后备字形。一般来说,最好避免依赖字体中特定符号的存在,而使用图像或内联 SVG - 正如您在“解决方案”中所做的那样。
关于python - Unicode 字符在 kivy python 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68572836/