Skip to content

Instantly share code, notes, and snippets.

@ckhung
Last active July 6, 2019 10:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ckhung/2800b4090fd9228f36fd to your computer and use it in GitHub Desktop.
Save ckhung/2800b4090fd9228f36fd to your computer and use it in GitHub Desktop.
在 kivy 程式裡面顯示中文
title=zh_TW_test
author=ckhung
orientation=landscape
# -*- coding: utf-8 -*-
# http://newtoypia.blogspot.tw/2015/07/kivy.html
import kivy
from kivy.app import App
from kivy.uix.button import Button
import kivy.resources
kivy.resources.resource_add_path('.')
class MyApp(App):
def build(self):
return Button(text=u'大大們安安', font_size=60, font_name=kivy.resources.resource_find('ukai.ttc'))
if __name__ == '__main__':
MyApp().run()
@TTFISHDES
Copy link

不行啊!

@TTFISHDES
Copy link

return Button(text=u'大大們安安', font_size=60, font_name=kivy.resources.resource_find('ukai.ttc'))
那個'u'是甚麼意思?

@TTFISHDES
Copy link

是不是只能用Button
TextInput 或是 label

@ckhung
Copy link
Author

ckhung commented Jul 6, 2019

u'大大們安安' 的 u 是指後面是 unicode 字串。 https://www.linuxtopia.org/online_books/programming_books/python_programming/python_ch12s02.html 從 python3 開始, 字串預設就是存成 utf8 , 所以那個 u 可以省略了: https://docs.python.org/3/howto/unicode.html

我改了一下 https://newtoypia.blogspot.com/2015/07/kivy.html 的文字,並且在這個 gist 加一個檔案,更明確地指出需要 main.py 跟 android.txt 這兩個檔案 (或是再加上 ukai.ttc)。 我只試過 label, 其他都沒試過。 這次我是在 essential ph-1 手機 lineage mata 作業系統上,安裝 kivy 1.9.0.0 上面 測試,是 ok 的。 這個最簡單陽春的版本,你成功嗎? 如果你試不出來, 請明確地描述你的 android 版本、 kivy 版本、 有沒有像其他範例一樣出現在 kivy 選單上、 ... 等等。 問問題時要提供詳細的資訊。

@TTFISHDES
Copy link

喔喔喔了解~,謝謝你拉~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment