[Python] Exception: ScrollView accept only one widget

Discussão em 'Python' iniciado por Stack, Março 22, 2025.

  1. Stack

    Stack Membro Participativo

    I have been making a rather large app for a school project due soon, and for some reason it keeps coming up with this error. This didn't come up when I ran the same program on another laptop (which I no longer have access to). The DropDowns use ScrollView widgets.

    The error messge when using debug is Exception: ScrollView accept only one widget pointing towards self.SM.add_widget(AppointmentsPage(name='AppointmentsPage'))

    Here is my relevant .kv:

    <SpoonieActionBar>:
    id: SpoonieActionBar
    MDFabBottomAppBarButton:
    icon: 'calendar-clock'
    on_press: root.parent.parent.manager.current = "AppointmentsPage"
    MDFabBottomAppBarButton:
    icon: 'pill'
    on_press: root.parent.parent.manager.current = "MedsPage"
    MDFabBottomAppBarButton:
    icon: 'home-heart'
    on_press: root.parent.parent.manager.current = "HomePage"
    MDFabBottomAppBarButton:
    icon: 'chart-line'
    on_press: root.parent.parent.manager.current = "TrackersPage"
    MDFabBottomAppBarButton:
    icon: 'cog'
    on_press: root.parent.parent.manager.current = "SettingsPage"

    <ShowUpcomingAppointments>:
    name: 'ShowUpcomingAppointments'
    RecycleBoxLayout:
    id: 'ShowUpcoming'
    size_hint_y: None

    <AppointmentsPage>:
    name: 'AppointmentsPage'
    on_pre_enter: root.appointments_enter()
    BoxLayout:
    orientation: 'vertical'
    ShowUpcomingAppointments:
    Button:
    text: 'Add appointment'
    on_press: root.manager.current = 'AddAppointmentPage'
    Button:
    text: 'Past Appointments'
    on_press: root.manager.current = 'PastAppointmentsPage'
    SpoonieActionBar:


    Here is the relevant .py:

    from kivy.uix.dropdown import ScrollView, DropDown
    from kivy.config import Config
    from kivy.uix.label import Label
    from kivy.uix.button import Button
    from kivy.uix.boxlayout import BoxLayout
    from kivy.uix.recycleview import RecycleView
    from kivy.uix.actionbar import ActionBar
    from kivymd.uix.appbar import MDTopAppBar, MDBottomAppBar, MDFabBottomAppBarButton
    from kivymd.icon_definitions import md_icons
    from kivy.uix.screenmanager import ScreenManager, Screen, FadeTransition
    from kivymd.app import MDApp
    import requests
    import json

    class SpoonieTrackerApp(MDApp):
    def __init__(self):
    super().__init__()
    self.sessionID = None
    self.SM = None

    def build(self):
    self.load_kv("spoonietracker.kv")
    self.theme_cls.theme_style_switch_animation = True
    self.theme_cls.theme_style = 'Dark'
    self.theme_cls.primary_palette = 'Indigo'

    self.SM = ScreenManager()
    # here are some more pages being added that are irrelevant
    self.SM.add_widget(TrackersPage(name='TrackersPage'))
    self.SM.add_widget(AppointmentsPage(name='AppointmentsPage'))
    self.SM.add_widget(EditAppointmentPage(name='EditAppointmentPage'))


    class ShowUpcomingAppointments(RecycleView):
    def currentappointments(self, appointments):
    def edit(self, instance):
    EditAppointmentPage.editappt_enter(appointment[0])
    app.SM.current = 'EditAppointmentPage'

    for appointment in range(len(appointments)+1):
    temp = appointments[appointment]
    currentappt = DropDown(self)
    layout = BoxLayout(orientation='vertical')
    # datetime
    layout.add_widget(Label(text=temp[0]))
    # doctor
    layout.add_widget(Label(text=temp[1]))
    if temp[3] is not None:
    # type
    layout.add_widget(Label(text=temp[3]))
    if temp[4] is not None:
    # place
    layout.add_widget(Label(text=temp[4]))
    if temp[2] is not None:
    # reason
    layout.add_widget(Label(text=temp[2]))
    if temp[5] is not None:
    # notes
    layout.add_widget(Label(text=temp[5]))

    editbutton = Button(text='Edit')
    editbutton.bind(on_press=edit)
    layout.add_widget(editbutton)
    final = BoxLayout(orientation='vertical')
    final.add_widget(layout)
    currentappt.add_widget(final)

    apptbutton = Button(text=str(temp[0]+' with '+temp[1]))
    apptbutton.bind(on_release=currentappt.open(self))
    self.ids.ShowUpcoming.add_widget(apptbutton)

    class AppointmentsPage(Screen):
    def appointments_enter(self):
    appointments = json.loads(requests.get('http://CyanUnicorn26.eu.pythonanywhere.com/appointments/current/',
    json={'SessionID':json.dumps(app.sessionID)},allow_redirects=True))
    ShowUpcomingAppointments.currentappointments(appointments)


    the json returns a list of lists, so it's not that either.

    I would really appreciate help with this, it must be something stupid I'm not seeing in the DropDown

    Continue reading...

Compartilhe esta Página