私のCurrentWeather
ウィジェット内の条件値にPythonの私のAddLocationForm
にアクセスするにはどうしたらいいですか? CurrentWeather
ではなく、AddLocationForm
から条件値を編集したいと考えています。これはこれまでのところ、私のコードです:キビの別のクラスにあるウィジェットにアクセスするにはどうすればいいですか
のPython:
from kivy.network.urlrequest import UrlRequest
import json
from kivy.core.window import Window
from kivy.uix.textinput import TextInput
from kivy.uix.listview import ListItemButton
from kivy.factory import Factory
Window.clearcolor = (0.45, 0.3, 1, 0.5)
class AddLocationForm(BoxLayout):
search_input = ObjectProperty()
search_results = ObjectProperty()
currentWeather = ObjectProperty()
def search_location(self):
search_template = "http://api.openweathermap.org/data/2.5/weather?q={}&appid=f8020ca79e2de4c1dd5a125c3f22fa18"
search_url = search_template.format(self.search_input.text)
request = UrlRequest(search_url, self.found_location)
def found_location(self, request, data):
data = json.loads(data.decode()) if not isinstance(data, dict) else data
weather = "%s" %(data["weather"][0]["description"])
root.WeatherRoot.CurrentWeather.conditions = weather #Problem is here
class LocationButton(ListItemButton):
pass
class WeatherApp(App):
def build(self):
global root
root = self.root
if __name__ == '__main__':
WeatherApp().run()
のKv:
#: import ListItemButton kivy.uix.listview.ListItemButton
#: import ListAdapter kivy.adapters.listadapter.ListAdapter
#: import main main
WeatherRoot:
<WeatherRoot>:
AddLocationForm
<AddLocationForm>:
orientation: "vertical"
search_input: search_box
search_results: search_results_list
BoxLayout:
height: "40dp"
size_hint_y: None
TextInput:
id: search_box
size_hint_x: 50
multiline: False
Button:
text: "Search"
size_hint_x: 25
on_press: root.search_location()
background_color: (1, 0.5, 0.656, 1)
<[email protected]>:
id: current_weather
currentWeather: current_weather
location: ""
conditions: ""
temp: None
temp_min: None
temp_max: None
orientation: "vertical"
Label:
text: root.location
pos_hint: {'x': 0.435, "y": 1}
font_size: '40dp'
size_hint_y: None
size_hint_x: None
BoxLayout:
orientation: "horizontal"
Label:
id: curCon
text: root.conditions
これは最小限の例ですか?これを参照してくださいhttp://stackoverflow.com/help/mcve – EL3PHANTEN
これは良いですか?私は学校に通っていたので、それは私には長い間反応していました。 –