I'm trying to make that if i click tab button the content of this tab will change. In this specific example, I want to change TextInput to day that it is today. But I have no clue how to execute function from WoPlan class in Menu class. Or just how to influence the WoPlan textinput via menu's button from tab.
.kv
<Menu>:
TabbedPanel:
do_default_tab: False
ORM:
font_size: 30
text: "ORM"
WoPlan:
font_size:30
text: "WOP"
on_press: root.WoPlan().weekday()
<WoPlan>:
BoxLayout:
orientation: "vertical"
TextInput:
id: weekday
disabled: True
.py
class WoPlan(TabbedPanelItem):
def weekday(self):
curr_date = date.today()
weekday = calendar.day_name[curr_date.weekday()]
self.ids.weekday.text = weekday
class Menu(Screen):
pass
CodePudding user response:
Instead of root.WoPlan().weekday()
, you can write self.weekday()
.
The "self" refers to the Widget, in which the on_press
is called ("WoPlan" in this case).
If you want to call the function from any other widget within the "Menu" Screen, e.g.:
<Menu>:
TabbedPanel:
do_default_tab: False
ORM:
font_size: 30
text: "ORM"
Button: #example widget
on_release: root.ids["woplan"].weekday()
WoPlan:
id: woplan
font_size:30
text: "WOP"
CodePudding user response:
I found out I can do that with current_tab: self.weekday()
I just needed to put it in here
<Menu>:
TabbedPanel:
do_default_tab: False
ORM:
font_size: 30
text: "ORM"
WoPlan:
font_size: 30
text: "WOP"
current_tab: self.weekday()