我正在尝试使用TabbedPanel类编写程序。我将使用ScreenManager和navbuttons来浏览每个选项卡中的不同屏幕。问题是什么都没有出现。起初至少NavLayout出现了,但现在出现的只是带有各自名称的选项卡。如何在选项卡中显示导航按钮和屏幕。
ex1.kv
<MainPanel>:
id: mp
usb_tab_wid: usb_tab
remote_tab_wid: remote_tab
sd_tab_wid: sd_tab
size_hint: 1,1
tab_width: 65
do_default_tab: False
tab_pos: 'top_right'
TabbedPanelItem:
id: usb_tab
text: 'Usb'
BoxLayout:
orientation: 'vertical'
UsbScreenManager:
NavLayout:
TabbedPanelItem:
id: remote_tab
text: 'Remote'
TabbedPanelItem:
id: sd_tab
text: 'SD'
<NavLayout>:
id: grid1
spacing: 5,5
rows: 1
size_hint: 1, .2
LeftButton:
id: left_arrow_button
Image:
source: 'left_arrow_iconb.png'
center: left_arrow_button.center
size: grid1.width*.8, grid1.height*.8
BackButton:
id: back_button
Image:
source: 'back_iconb.png'
center: back_button.center
size: grid1.width*.8, grid1.height*.8
RightButton:
id: right_arrow_button
Image:
source: 'right_arrow_iconb.png'
center: right_arrow_button.center
size: grid1.width*.8, grid1.height*.8
usb.kv
<UsbScreenManager>:
id: usb_screen_manager
H2HScreen:
name: 'h2h'
V9validationScreen:
name: 'v9'
<H2HScreen>:
name: 'h2h'
BoxLayout:
TestIcon:
source: 'h2h.png'
<V9validationScreen>:
name: 'v9'
BoxLayout:
Label:
text: 'V9 tests'
ex1.py
import kivy
kivy.require('1.9.0')
import subprocess
import csv
from datetime import datetime
import usb.core
import usb.util
import threading
import time
from functools import partial
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.behaviors import ButtonBehavior
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.properties import ObjectProperty, StringProperty, NumericProperty
from kivy.clock import Clock
from kivy.uix.image import Image
from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
from kivy.lang import Builder
from kivy.app import App
from kivy.uix.tabbedpanel import TabbedPanel
from kivy.uix.boxlayout import BoxLayout
class MainPanel(TabbedPanel):
usb_tab_wid = ObjectProperty()
remote_tab_wid = ObjectProperty()
sd_tab_wid = ObjectProperty()
usbman = ObjectProperty(None)
def switch_to(self, header):
pass
def print_wd(self):
for widget in self.walk():
print("[]->{}".format(widget, widget.id))
def on_current_tab(self, b, c):
print(self.current_tab)
#return super(MainPanel, self).on_current_tab()
#print(usb_tab_wid)
pass
class TestIcon(ButtonBehavior, Image):
pass
class UsbScreenManager(ScreenManager):
pass
class H2HScreen(Screen):
pass
class V9validationScreen(Screen):
pass
class RemoteScreenManager(ScreenManager):
pass
class SDcardScreenManager(ScreenManager):
pass
class NavLayout(GridLayout):
pass
class LeftButton(Button):
sm = ObjectProperty()
mp = MainPanel()
ct= mp.current_tab
#print (ct)
pass
class RightButton(Button):
sm = ObjectProperty()
panel = ObjectProperty()
pass
class BackButton(Button):
sm = ObjectProperty()
panel = ObjectProperty()
def active_panel():
#if current tab is __ then load corresponding screen manager
pass
pass
class Sam1App(App):
def build(self):
return MainPanel()
Builder.load_file("usb.kv")
if __name__ == '__main__':
Sam1App().run()
答案 0 :(得分:1)
我发现我覆盖了TabbedPanel的switch_to方法,但没有定义任何内容。所以TabbedPanel不知道要切换到什么,所以它什么都没显示。