python - Kivy Python 使用按钮打开 .kv 文件来更改 GUI
问题描述
我正在尝试使用一个按钮在屏幕上循环显示 GUI 这是我尝试使用主文件然后使用 2 个额外文件的代码。代码本身有效,我不断收到“未定义生成器”错误,该错误不会将新文件加载到屏幕上
目标是有一个按钮,它将屏幕切换到下一个屏幕并再次返回
任何帮助深表感谢
主文件
# import subprocess
# import kivy
from kivy.uix.button import Button
from kivy.app import App
from kivy.lang import Builder
from kivy.properties import NumericProperty
from kivy.uix.floatlayout import FloatLayout
from kivy.config import Config
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', '600')
Config.set('graphics', 'height', '300')
class CustomRow(FloatLayout):
pass
class CustomGrid(FloatLayout):
pass
class RotationApp(App):
OilTemp = NumericProperty(0)
print(OilTemp)
def build(self):
print("building...")
return Builder.load_file('oiltemp.kv')
# the __name__ idiom executes when run from command line but not from import.
if __name__ == '__main__':
RotationApp().run()
第二个文件
<oiltemp>:
CustomRow:
FloatLayout:
id: 0
FloatLayout:
id: 1
# etc, creating as many FloatLayouts as many number of columns you want.
CustomGrid:
CustomRow:
id: 0
CustomRow:
id: 1
Image:
source: 'OilTempV2.png'
size: self.texture_size
Image:
source: 'NeedleV1.png'
size: self.texture_size
pos_hint: {'center_x': .5, 'center_x': .5}
Button:
text: 'Next Screen'
size_hint: None, None
pos_hint: {'left_x': .5, 'bottom_y': .5}
canvas.before:
PushMatrix
Rotate:
angle: 0
origin: self.center
canvas.after:
PopMatrix
第三个文件
<airtemp>:
CustomRow:
FloatLayout:
id: 0
FloatLayout:
id: 1
# etc, creating as many FloatLayouts as many number of columns you want.
CustomGrid:
CustomRow:
id: 0
CustomRow:
id: 1
Image:
source: 'AirTempV1.png'
size: self.texture_size
Image:
source: 'NeedleV1.png'
size: self.texture_size
pos_hint: {'center_x': .5, 'center_x': .5}
Button:
text: 'Next Screen'
size_hint: None, None
pos_hint: {'left_x': .5, 'bottom_y': .5}
canvas.before:
PushMatrix
Rotate:
angle: 0
origin: self.center
canvas.after:
PopMatrix
解决方案
推荐阅读
- javascript - 如何在 xdsoft 的 datetimepicker 中将时间设置为 00 格式?
- javascript - 三元运算符 React Native 中的多个条件
- c++ - if 和 else 用户验证问题
- python - Python 应用程序如何使用 Docker-compose 找到 Postgres 数据库
- flutter - 通过自动格式化将 Dart/Flutter 函数链接到新行
- excel - VBA 数据输入表单获取运行时错误“91”:
- excel - 具有多个变量的 VBA Goalseek 循环
- html - 如何从选择框中显示选定的值?
- php - include_path='.:/usr/share/pear:/usr/share/php' 托管站点后出现错误
- reactjs - Form.Field 组件超出范围