kivy:打开(文件名,编码='utf-8')不起作用

时间:2018-08-10 13:01:30

标签: python encoding kivy

我的python版本是3.6

如果我在.kv文件中写韩语

并输入python

Builder.load_file("Bus_Information.kv")

..它不起作用。

然后我在下面找到了这样的解决方案

with open('Bus_Information.kv', encoding='utf-8') as f:
    Builder.load_string(f.read())

,不再有错误。但在屏幕上,只有断的字母。 enter image description here就是这样。

我该如何解决?谢谢您的阅读。

py文件

from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.animation import Animation
from kivy.clock import Clock
#from kivy.config import Config
#Config.set('graphics', 'resizable', 0)
from kivy.core.window import Window
Window.size = (486, 650) 

class Loading_Screen(Screen):
    def __init__(self, **kwargs):
        super(Loading_Screen, self).__init__(**kwargs)
        Clock.schedule_once(self.callNext, 2) 
    def callNext(self,dt):
        self.manager.current = 'Before_First_Screen'

class Load_BusInfo():
    pass

class Before_First_Screen(Screen):
    pass

class First_Screen(Screen):
    pass

class Test_Screen(Screen):
    pass

class DTN_TECHNOPARK(Screen): 
    pass

class DTN_BITZONE(Screen): 
    pass

class DTN_INUSTATION(Screen): 
    pass

class Bus_Information(Screen): ####<---Here is the problem.####
    with open('Bus_Information.kv', encoding='utf-8') as f:
        Builder.load_string(f.read())
    #Builder.load_file("Bus_Information.kv")

class ScreenManagement(ScreenManager):
    pass

presentation = Builder.load_file("main.kv")

class TubucApp(App):
    def build(self):
        return presentation

TubucApp().run()

这是.kv文件

<Bus_Information>:
    name: 'Bus_Information'
    canvas:
        Rectangle:
            pos: self.pos
            size: self.size 
            source: 'image/destination/a.png' #backgroundimage
    Label:
        text_size: cm(6), cm(4)
        #halign: 'right'                
        #valign: 'middle'           
        pos: [1, 1]
        id: my_custom_label
        text: '가나다라마바사' ##here is broken letters..##
        color: [255,255,255,1]

我尝试过

  1. u'가나다라마바사'

  2. # -*- coding: utf-8 -*-

0 个答案:

没有答案