-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TabbedPanel.switch_to() does not appear to work #3493
Comments
You are inheriting from the widget and trying to add to the widget before it has finished setting up in You need to let the widget initiate completely and then add your tabs to it. first tab added is selected by default. This would be automatically taken care of if you used kv. Just look at the examples |
ok, kind of got it, but am still not entirely sure of how to do it in pure python. Although the "kv-language" seems very easy on the simple examples,I cannot wrap my head around how it works in more complex examples at the moment.
To: kivy/kivy kivy@noreply.github.com You are inheriting from the widget and trying to add to the widget before it has finished setting up in init.You need to let the widget initiate completely and then add your tabs to it. first tab added is selected by default.This would be automatically taken care of if you used kv.Just look at the examples examples/widgets/tabbed*... — |
@ahed87 this is one way: from functools import partial
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel, TabbedPanelHeader
from kivy.clock import Clock
class mainw(TabbedPanel):
def __init__(self, **kwargs):
super(mainw, self).__init__(**kwargs)
self.do_default_tab = False
self.tab_width = 150
# create the tabs
tab1 = TabbedPanelHeader(text='tab1')
self.add_widget(tab1)
tab2 = TabbedPanelHeader(text='tab2')
self.add_widget(tab2)
Clock.schedule_once(partial(self.switch, tab1), 0)
def switch(self, tab, *args):
self.switch_to(tab)
class tbpApp(App):
def build(self):
return mainw()
if __name__ == '__main__':
tbpApp().run() If you have further questions, visit our support channels: https://github.com/kivy/kivy#support. |
Great thanks a lot for that working example! Although it did actually not work with 0 (=next frame) as time on my computer, Seeing full examples in work where a particular issue is adressed is for me by far the best way to be able to get a full understanding for what needs to be done in different cases. PS: I did try once or twice with clock, but never seriously tried also with partial, missed that part |
How would we know this by reading the documentation? And why close this? It's still broken for some indeterminate time after you've initialized it, and there's no way to tell when it's "not broken". |
How would we know this by reading the documentation? And why close this? |
Hmm, yeah this needs to be documented. |
I'll try to document it as my first contribution to kivy! |
Yeah, in |
* Fixed reference Previous reference didn't link to anywhere, and now it links to the dev-install page. * Added link for example usage As discussed in the issue #3493, when calling this method from the python script, it has to be scheduled to the next clock cycle. * Update kivy/uix/tabbedpanel.py Co-authored-by: matham <moiein2000@gmail.com> Co-authored-by: matham <moiein2000@gmail.com>
* Fixed reference Previous reference didn't link to anywhere, and now it links to the dev-install page. * Added link for example usage As discussed in the issue kivy#3493, when calling this method from the python script, it has to be scheduled to the next clock cycle. * Update kivy/uix/tabbedpanel.py Co-authored-by: matham <moiein2000@gmail.com> Co-authored-by: matham <moiein2000@gmail.com>
Was documented in Jan 2021. Closing as fixed. |
Hi,
first of all I would like to congratulate on the great work that kivy is, keep it up!!
I really hope that it will grow further and become the natural choise for python and gui's.
Using the code below, when the code has run, "tab1" is not selected.
I'm running windows portable installation Kivy-1.9.0-py3.4-win32-x64 and have w8.1
It works fine to select the tab manually.
Maybe .switch_to is not meant to make the tab active, but at least I would assume that this is what it does.
I also made some smaller attempts to see if I could make it selected/active with some of the other methods in TabbedPanel, but could not get it to work.
I decided to skip the "default_tab" (which by the way is preselected also on my computer), since I did not want different ways to assign the tabs.
Is this a bug, or can I get the tab selected another way (not using default tab)?
The text was updated successfully, but these errors were encountered: