Привет, у меня есть код:
import pyowm
from pyowm.owm import OWM
from pyowm.utils.config import get_config_from
from kivy.lang import Builder
from kivy.uix.floatlayout import FloatLayout
from kivymd.uix.button import MDIconButton
from kivymd.app import MDApp
from kivymd.uix.tab import MDTabsBase
config_dict = get_config_from('config.json')
owm = pyowm.OWM('ed3d1e950f0d1e73b26cfd7f55fbb4f9', config_dict)
mgr = owm.weather_manager()
kv = '''
BoxLayout:
orientation: "vertical"
MDToolbar:
title: "View Allthings"
MDIconButton:
icon: "youtube"
theme_text_color: "Custom"
md_text_color: 2, 9, 6, 1
icon_size: 1.2, 1.9
on_press: app.on_start()
MDTabs:
id: tab
<w>:
FloatLayout:
id: fl
MDTextField:
hint_text: "Название города"
text: ""
mode: "rectangle"
id: ccity
pos_hint: {'y': .90, 'x': .3}
size_hint: .4, .067
MDIconButton:
icon: "check-bold"
pos_hint: {'y': .89, 'x': .75}
on_press: root.update()
MDGridLayout:
rows: 4
size_hint_y: .8
spacing: 200
padding: 30
pos_hint: {'y': .03, 'x': .05}
MDIcon:
icon: "thermometer-low"
MDIcon:
icon: "check-bold"
MDIcon:
icon: "twitter"
MDIcon:
icon: "discord"
MDGridLayout:
cols: 2
rows: 4
spacing: 100
size_hint: .9, .8
md_bg_color: 0, 0, 0, .2
pos_hint: {'y': .03, 'x': .05}
MDLabel:
id: label
text: " Температура сейчас"
halign: "center"
MDLabel:
id: res
text: "None"
halign: "center"
MDLabel:
id: label2
text: "Min/max "
halign: "center"
MDLabel:
id: res4
text: "None"
halign: "center"
MDLabel:
id: label4
text: "Tab"
halign: "center"
MDLabel:
id: res1
text: "None"
halign: "center"
MDLabel:
id: label6
text: "Tab"
halign: "center"
MDLabel:
id: res2
halign: "center"
'''
class w(FloatLayout, MDTabsBase):
def update(self):
if (self.ids.ccity.text == ""):
city = "Ню Йорк"
else:
city = str(self.ids.ccity.text)
observation = mgr.weather_at_place(city)
w = observation.weather
l = w.temperature('celsius')['temp']
temp = str(l) + " °C"
self.ids.res.text = str(temp)
class k(FloatLayout, MDTabsBase):
pass
ws = w()
class Main(MDApp):
n = 3
def build(self):
return Builder.load_string(kv)
def on_start(self):
file = open('city.txt', 'r', encoding='utf-8')
nms = ["Курс биткоина", "Курс доллара и эвро", "Коронавирус", "Погода"]
w1 = self.root.ids.tab.add_widget(w(text=nms[self.n]))
self.n -= 1
w2 = self.root.ids.tab.add_widget(k(text=nms[self.n]))
txtc = str(file.read())
pass
if __name__ == '__main__':
Main().run()
Мне нужно чтобы в TextField(он в классе "w"), при старте, задавалась переменная из класса Main(txtc)
На file.load не обращайте внимания