【发布时间】:2017-01-10 21:41:49
【问题描述】:
kivy 中有些东西我不明白,希望有人能解释一下。我已经阅读了很多关于这个主题的内容,但它似乎并没有在我的脑海中联系起来。
我的问题来自将函数链接到 kivy 按钮。 现在我正在尝试学习如何做一个简单的功能:
def Math():
print 1+1
我想做一些更复杂的事情:
def Math(a,b):
print a^2 + b^2
其中a 和b 是来自kivy 的输入标签,单击按钮后将打印答案。
这是我目前所拥有的:
from kivy.app import App
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.uix.widget import Widget
from kivy.uix.floatlayout import FloatLayout
#######``Logics``#######
class Math(FloatLayout):
def add(self):
print 1+1
#######``Windows``#######
class MainScreen(Screen):
pass
class AnotherScreen(Screen):
pass
class ScreenManagement(ScreenManager):
pass
presentation = Builder.load_file("GUI_Style.kv")
class MainApp(App):
def build(self):
return presentation
if __name__ == "__main__":
MainApp().run()
这是我的 kivy 语言文件:
import NoTransition kivy.uix.screenmanager.NoTransition
ScreenManagement:
transition: NoTransition()
MainScreen:
AnotherScreen:
<MainScreen>:
name: "main"
FloatLayout:
Button:
on_release: app.root.current = "other"
text: "Next Screen"
font_size: 50
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
pos_hint: {"right":1, "top":1}
<AnotherScreen>:
name: "other"
FloatLayout:
Button:
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
text: "add"
pos_hint: {"x":0, "y":0}
on_release: root.add
Button:
color: 0,1,0,1
font_size: 25
size_hint: 0.3,0.2
text: "Back Home"
on_release: app.root.current = "main"
pos_hint: {"right":1, "top":1}
【问题讨论】:
标签: python kivy kivy-language