Nov-24-2018, 06:23 PM
^_^
The call needed a lambda function, and i was passing it a normal function!
That was the error.
Thank you sir :D
But then running my code puts everything into the same side. I'll attach picture of the output. I want it to come on the right side and i want it to be scrollable.
Here is my semi-fiexed code and its output.
The call needed a lambda function, and i was passing it a normal function!
That was the error.
Thank you sir :D
But then running my code puts everything into the same side. I'll attach picture of the output. I want it to come on the right side and i want it to be scrollable.
Here is my semi-fiexed code and its output.
from kivy.app import App from kivy.lang import Builder from kivy.uix.widget import Widget from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout import openpyxl root = Builder.load_string(''' <RootWid>: orientation: 'vertical' ActionBar: pos_hint: {'top':1} ActionView: use_separator: True ActionPrevious: title: 'StuCheck' with_previous: False ActionOverflow: ActionButton: text: 'Populate list' ActionButton: text: 'Sort list' ActionButton: text: 'Clear list' BoxLayout: orientation: 'horizontal' ScrollView: Widget1: ScrollView: Widget2: <Widget1>: orientation: 'vertical' <Widget2>: orientation: 'vertical' ''') class RootWid(BoxLayout): pass class Widget1(BoxLayout): def __init__(self, **kwargs): super(Widget1, self).__init__(**kwargs) subjects = ['Anatomy', 'Biochemistry', 'Physiology', 'Pharmacology', 'Pathology', 'Microbiology', 'FMT', 'Ophthalmology', 'ENT', 'PSM', 'OG', 'Surgery', 'Internal_Medicine', 'Paediatrics', 'Anaesthesiology', 'Radiology', 'Dermatology', 'Orthopaedics', 'Psychiatry'] for subject in subjects: btn = Button(text=subject, on_release= lambda x: self.populate(subject)) Widget1.add_widget(self, btn) def populate(self, subject): wb = openpyxl.load_workbook('sWL.xlsx') sheet = wb[subject] data = [] for row in range (2, sheet.max_row+1): question = sheet.cell(row=row, column=1).value data.append(question) return self.make_buttons(data) def make_buttons(self, data_list): self.clear_widgets() for question in data_list: btn = Button(text=question) Widget2().add_widget(self, btn) class Widget2(BoxLayout): pass class TestApp(App): def build(self): return RootWid() if __name__ == '__main__': TestApp().run()