kivy中的应用程序名称
Application name in kivy
我有两个应用程序和一个 kv 文件。两个应用程序之间仅在应用程序 class 名称中有所不同。应用程序 A 的结果很好,但应用程序 B 的结果很差。问题出在哪里?
应用程序 A:
import kivy
kivy.require('1.0.5')
from kivy.lang.builder import Builder
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ShowApp().run()
应用程序 B:
import kivy
kivy.require('1.0.5')
from kivy.lang.builder import Builder
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ControlShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ControlShowApp().run()
KV 文件:
<MyW>
cols: 2
rows: 2
Button:
id: label1
text: 'B1'
Button:
id: label2
text: 'B2'
Button:
id: label3
text: 'B3'
Button:
id: label4
text: 'B4'
问题如下:
- 一个 class 规则,由 < > 之间的小部件 class 的名称声明,后跟:例如<我的W>:
- 缩进4个空格
例子
ControlShow.kv
#:kivy 1.10.0
<MyW>:
cols: 2
rows: 2
Button:
id: label1
text: 'B1'
Button:
id: label2
text: 'B2'
Button:
id: label3
text: 'B3'
Button:
id: label4
text: 'B4'
ShowApp.py
from kivy.lang.builder import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ShowApp().run()
控制ShowApp.py
from kivy.lang.builder import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ControlShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ControlShowApp().run()
输出
我有两个应用程序和一个 kv 文件。两个应用程序之间仅在应用程序 class 名称中有所不同。应用程序 A 的结果很好,但应用程序 B 的结果很差。问题出在哪里?
应用程序 A:
import kivy
kivy.require('1.0.5')
from kivy.lang.builder import Builder
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ShowApp().run()
应用程序 B:
import kivy
kivy.require('1.0.5')
from kivy.lang.builder import Builder
from kivy.uix.button import Button
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ControlShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ControlShowApp().run()
KV 文件:
<MyW>
cols: 2
rows: 2
Button:
id: label1
text: 'B1'
Button:
id: label2
text: 'B2'
Button:
id: label3
text: 'B3'
Button:
id: label4
text: 'B4'
问题如下:
- 一个 class 规则,由 < > 之间的小部件 class 的名称声明,后跟:例如<我的W>:
- 缩进4个空格
例子
ControlShow.kv
#:kivy 1.10.0
<MyW>:
cols: 2
rows: 2
Button:
id: label1
text: 'B1'
Button:
id: label2
text: 'B2'
Button:
id: label3
text: 'B3'
Button:
id: label4
text: 'B4'
ShowApp.py
from kivy.lang.builder import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ShowApp().run()
控制ShowApp.py
from kivy.lang.builder import Builder
from kivy.uix.gridlayout import GridLayout
from kivy.app import App
class MyW(GridLayout):
pass
class ControlShowApp(App):
def build(self):
Builder.load_file('d:\MyPgm\Python\kivy\ControlShow \ControlShow.kv')
return MyW()
if __name__ == '__main__':
ControlShowApp().run()