Does not display Cyrillic in kivy in utf-8
There are two files, main.py and my. kv. I work in a paycharm. Both files have utf-8.
The code is clean, everything is at a minimum:
# -*- coding: utf-8 -*-
from kivy.app import App
from kivy.uix.gridlayout import GridLayout
class Container(GridLayout):
pass
class MyApp(App):
def build(self):
return Container()
if __name__ == '__main__':
MyApp().run()
Well, my. kv:
<Container>:
BoxLayout:
Label:
text: 'текст'```
Windows 8.1
upd; конвертация .kv файла в windows1251 решила проблему, но теперь вопрос вот в чём. не отразится ли это на чём нибудь в будущем?
0
1 answers
In general, in most cases, changing the encoding from windows-1251 to utf-8 helps, but it can be the other way around, as in my example.
Also, for windows 10, the method from another question may work: Windows Settings -> Time and language -> Language -> Administrative language settings -> Change the system language. Here we check the box "Beta version: Use Unicode (UTF-8) to support the language worldwide" and restart the computer.
Plus, there is also such a frequently recommended option:
with open('kv_file.kv', encoding='utf-8') as kv_file:
kv_file.read()
And here is another method:
def load_all_kv_files(self, directory_kv_files):
for kv_file in os.listdir(directory_kv_files):
kv_file = os.path.join(directory_kv_files, kv_file)
if os.path.isfile(kv_file) and kv_file.endswith("kv"):
with open(kv_file, encoding="utf-8") as kv:
Builder.load_string(kv.read())
1
Author: type49, 2020-04-16 01:02:34