我的代码点亮了一个 LED。这个程序在 Tkinter 中有效,但当我用 Kivy 编写它时它不起作用!!问题是什么?kivy.py ==>from kivy.app import Appfrom kivy.lang import Builderfrom kivy.uix.screenmanager import ScreenManager, Screenimport requestsclass MainWindow(Screen): passclass WindowManager(ScreenManager): passkv = Builder.load_file("my9.kv")class MyMainApp(App): def build(self): return kvif __name__ == "__main__": MyMainApp().run()我的.kv==>WindowManager: MainWindow:<MainWindow>: name: "main" GridLayout: cols:1 Button: text: "Submit" TheRequest = requests.get('http://192.168.43.91/on')错误 ==> 文件“/home/pi/Desktop/ali/my9.kv”,第 13 行,在 TheRequest = requests.get('http://192.168.43.91/on') NameError: name 'requests' is not定义的
1 回答
慕森卡
TA贡献1806条经验 获得超8个赞
您需要kv 文件中的import模块requests。并且还在 的方法TheRequest = requests.get('http://192.168.43.91/on')下添加语句。修改后的 kv 文件如下所示:on_releaseButton
#:import requests requests
WindowManager:
MainWindow:
<MainWindow>:
name: "main"
GridLayout:
cols:1
Button:
text: "Submit"
on_release:
TheRequest = requests.get('https://www.android.com/')
添加回答
举报
0/150
提交
取消