我正在编写一个应用程序,允许教师创建一个学年,在一年内添加几个课程,他可以在其中添加几个学生。有3种类型的对象:School_Year,Class,Student。除了Student之外,所有这些对象都由树中包含子对象的目录表示。
Tree architecture:
School_Year / Class / Student
以下是我想要做的事情:
1。有一个显示所有年份的主菜单,允许添加/删除年份。当您点击一年时,它会显示今年的所有课程:
2。想象一下,你点击2010 - 2011年。它创建了一个递归菜单,2012-2013被推向了底层:
第3。想象一下,你点击" A级" ,它会显示这个clas的学生列表和另一个递归菜单,以及" B"被推到底部
我无法做到这一点,因为我在kivy的新手太多但我尝试了第一级递归: 的的.py:
# coding: utf-8
from kivy.app import App
from kivy.lang import Builder
from kivy.clock import Clock
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.uix.button import Button
from kivy.uix.spinner import Spinner
from functools import partial
class GUI(ScreenManager):
def __init__(self, **kwargs):
super(GUI, self).__init__(**kwargs)
class Home(Screen):
def __init__(self, **kwargs):
super(Home, self).__init__(**kwargs)
# add a school year (parent "folder") on the home menu
def add_year(self, grid, classname):
# button of the year
""" The values of this spinner are temporary, I don't know how to insert other child spinners inside
I think I must replace the spinner by a Drop Down but I can't do it, I need some help"""
left = Spinner(values = ["?", "??", "???"], text=classname.text, size = (32, 32), size_hint = (1, None))
# the delete button of this year
right = Button(background_color = (1,0,0,1), text="X", size = (32, 32), size_hint = (None, None))
# equivalent of: on_press = self.del_year(grid, left, right) without NoneType error
right.bind(on_press=partial(self.del_year, grid, left, right))
# add these 2 buttons to the GridLayout
grid.add_widget(left)
grid.add_widget(right)
# clear bottom's TextInput
classname.text = ""
# remove a school year from the home menu
def del_year(self, grid, L, R, *args):
# remove the two buttons from the GridLayout (year name button and delete button)
grid.remove_widget(L)
grid.remove_widget(R)
# load kivy file
Builder.load_file("nouv_test.kv")
class RunApp(App):
def build(self):
return GUI()
if __name__ == '__main__':
RunApp().run()
.kv:
#: kivy 1.10.0
<GUI>:
Home:
name: "home_screen"
id: home
<Home>:
GridLayout:
rows: 3
Button:
text: "MY YEARS"
size: (50, 50)
size_hint: (1, None)
background_color: (0.2, 0.2, 0.8, 1)
ScrollView:
size_hint:(1, .8)
pos_hint: {'center_x': 0.5, 'center_y': 0.5}
do_scroll_x: False
GridLayout:
id: home_scroll_grid
cols: 2
padding: 5
spacing: 5
height: self.minimum_height
size_hint: (1, None)
BoxLayout:
padding: 5
spacing: 5
size: (42, 42)
size_hint: (1, None)
TextInput:
id: year_name
size: (32, 32)
size_hint: (1, None)
multiline: False
Button:
text: "+"
background_color: (0,1,0,1)
size: (32, 32)
size_hint: (None, None)
on_press: root.add_year(home_scroll_grid, year_name)
我提供了尽可能多的信息,因为我的问题非常具体,并且不常见,因为很少使用这样的图形递归。那么有人可以给我一些方法来尝试这样做吗?感谢。