Answer the question
In order to leave comments, you need to log in
How to solve UnicodeDecodeError for cyrillic in kv file?
Given:
This tutorial. In English it works without nit-picking, in Russian - no. :\ Don't be silly, I googled and found the solution .
And after all, in theory, not bad: manually read the file in the desired encoding. But it was not there. It works for everyone, but not for me (as always). :D
Warning the proposal on the latest proposed solution in the branch - prescribe the desired text in the .ru-file, and then refer to it in .kv. It is not even considered, because this example was needed to understand who this kv of yours is. Understood. And then the entire interface should be in Russian (I would write in English, but the commission on the defense of the diploma will hardly understand this attack. :D).
The code:
#main.py
# -*- coding: utf-8 -*-
import kivy
from kivy.app import App
from kivy.uix.label import Label
from kivy.uix.gridlayout import GridLayout
from kivy.uix.textinput import TextInput
from kivy.uix.button import Button
from kivy.lang import Builder
from kivy.uix.widget import Widget
class MyGrid(Widget):
pass
with open("my.kv", encoding='utf8') as f:
my = Builder.load_string(f.read())
class MyApp(App):
def build(self):
return my
if __name__ == "__main__":
MyApp().run()
#my.kv
#encoding: utf-8
<MyGrid>:
GridLayout:
cols:1
size: root.width, root.height
GridLayout:
cols:2
Label:
text: "Имя: "
TextInput:
multinline:False
Label:
text: "Е-майл: "
TextInput:
multiline:False
Button:
text:"Submit"
Answer the question
In order to leave comments, you need to log in
Judging by the error and the code, your python swears not at your decision:
with open("my.kv", encoding='utf8') as f:
my = Builder.load_string(f.read())
For example, say you have a file named main.py that contains::
class ShowcaseApp(App): pass
This method will search for a file named `showcase.kv` in
the directory that contains main.py. The name of the kv file has to be
the lowercase name of the class, without the 'App' postfix at the end
if it exists.
class MyApp(App):
def build(self):
return my
def load_kv(self, *args, **kwargs):
pass
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question