【发布时间】:2021-01-03 12:42:18
【问题描述】:
我正在使用 Python 3.9 和 Kivy
from kivy.config import Config
Config.set('graphics', 'resizable', False)
Config.set('graphics', 'width', 800)
Config.set('graphics', 'height', 600)
Config.set('input', 'mouse', 'mouse,multitouch_on_demand')
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.uix.widget import Widget
from kivy.core.window import Window
from kivy.properties import ObjectProperty
from kivy.lang import Builder
import subprocess
presentation = Builder.load_file('UI_1.kv')
#Calling files to open
#Always use popen
class presentation(Widget):
maths = ObjectProperty(None)
physics = ObjectProperty(None)
def btn_touch_up(maths):
from subprocess import Popen, PIPE
subprocess.Popen(['python', 'UI_MATH.py'])
exit()
def btn_touch_up(physics):
from subprocess import Popen, PIPE
subprocess.Popen(['python', 'UI_PHYSICS.py'])
exit()
class MyApp(App):
def build(self):
return presentation()
Window.clearcolor = (1, 1, 1, 1)
if __name__ == "__main__":
MyApp().run()
这就是我写的代码。问题是当我运行应用程序并单击第一个框(标记为数学)时,打开 2 框的代码(物理)。当我为第二个盒子(物理)计时时,它运行正确的代码。有人可以指出我的错误以便我纠正吗?我还很新,所以我的代码可能看起来很乱......
这是来自 kivy (.kv) 文件的代码:
<presentation>
maths : maths
physics : physics
extra : extra
canvas:
Color:
rgb:0,0,0
Rectangle:
pos:8,498
size:790,50
Rectangle:
pos:8,398
size:790,50
Rectangle:
pos:8,298
size:790,50
GridLayout:
cols:1
size: root.width -10, root.height -550
pos: 5, 500
GridLayout:
cols:1
Button:
id: maths
text:"1.Maths"
on_press: root.btn_touch_up()
GridLayout:
cols:1
size: root.width -10, root.height -550
pos: 5, 400
GridLayout:
cols:1
Button:
id: physics
text:"2.Physics"
on_press: root.btn_touch_up()
GridLayout:
cols:1
size: root.width -10, root.height -550
pos: 5, 300
GridLayout:
cols:1
Button:
id: extra
text:"3.Extra"
on_press: root.btn_touch_up()
再次感谢您,我真的是新手,而且是自学成才的,所以如果有明显不应该做的错误,请指出。
【问题讨论】: