J
J
Just Python's sheep2020-07-19 12:21:50
Python
Just Python's sheep, 2020-07-19 12:21:50

KivyMD - TypeError: update() missing 4 required positional arguments: 'instance_tabs', 'instance_tab', 'instance_tab_label', and 'tab_text'?

Hello, in kivymd I am making Tabs, and to update I need a button (I made a weather parser), everything worked on updating via on_tab_switch, but now I wanted to do it via a button, and an error pops up:

TypeError: update() missing 4 required positional arguments: 'instance_tabs', 'instance_tab', 'instance_tab_label', and 'tab_text'


And here is the code:

import pyowm

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

kv = '''
BoxLayout:
    orientation: "vertical"

    MDToolbar:
        title: "View Allthings"

    MDTabs:
        id: tab
        on_tab_switch: app.update()

<w>:
  FloatLayout:
      MDIconButton:
      	icon: "update"
   		 theme_text_color: "Custom"
    		text_color: app.theme_cls.primary_color
    		on_press: app.update()
    		
      MDTextField:
      	hint_text: "Название города"
      	mode: "rectangle"
      	id: ccity
      	pos_hint: {'y': .93, 'x': .3}
      	size_hint: .4, .067
    	MDLabel:
    		pos_hint: {'y': .0, 'x': .0}
      	  id: label
      	  text: "Tab"
       	 halign: "center"
'''
    
class w(FloatLayout, MDTabsBase):
  pass
  
class k(FloatLayout, MDTabsBase):
  pass


class Main(MDApp):
    n = 3

    def build(self):
        return Builder.load_string(kv)

    def on_start(self):
    	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]))
    def on_tab_switch(
        self, instance_tabs, instance_tab, instance_tab_label, tab_text
    ):
    	instance_tab.ids.label.text = tab_text
    def update(self, instance_tabs, instance_tab, instance_tab_label, tab_text):
    	owm = pyowm.OWM('ed3d1e950f0d1e')
    	city = str(instance_tab.ids.ccity.text)
    	mgr = owm.weather_manager()
    	observation = mgr.weather_at_place(city)
    	w = observation.weather
    	l = w.temperature('celsius')['temp']
    	temp = "Температура в городе " + city + '\n' + str(l) + " градусов"
    	instance_tab.ids.label.text = str(temp)

if __name__ == '__main__':
  Main().run()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question