我的目标是减少一个相对下降的菜单和“+” but子,把“+”icon改为一个新的下降项目,并在此之后重新出现“+”icon,准备增加第三个减小项目。
I ve been on this for a while. I ve tried a custom widget but i might have gotten the code wrong.. I ve tried a method to build the MDDropDownItem and many more. The problem is always a KeyError: label_item . As it seems, a MDDropDownItem doesn t get inizialized with this property if it s created in the python file... this seems weird to me, so here I am!
其次,将产生错误的最简单方式放下一米。 如果有人能够解决这个问题,那将令人惊讶!
档案:
from kivymd.app import MDApp
from kivy.lang import Builder
from kivymd.uix.boxlayout import MDBoxLayout
from kivymd.uix.relativelayout import RelativeLayout
from kivymd.uix.screen import MDScreen
from kivymd.uix.label import MDLabel
from kivymd.uix.textfield import MDTextField
from kivymd.uix.button import MDIconButton
from kivymd.uix.menu import MDDropdownMenu
from kivymd.uix.dropdownitem import MDDropDownItem
from kivymd.uix.selectioncontrol import MDCheckbox
import sqlite3
import os
class ExampleApp(MDApp):
def build(self):
return Builder.load_file( example.kv )
def set_dropmenutext(self, text):
self.root.ids.types_dropdownmenu.text = text
self.menu.dismiss()
def open_menu(self, call):
menu_items = [{"text": i,
"viewclass": "OneLineListItem",
"on_release": lambda x= i: self.set_dropmenutext(x)} for i in ["INTEGER", "REAL", "TEXT", "BLOB", "NULL"]]
self.menu = MDDropdownMenu(
caller=call,
items=menu_items,
width_mult=4,
position="auto")
self.menu.open()
def add_column(self):
grid = self.root.ids.column_grid
add_btn = self.root.ids.add_col
grid.remove_widget(add_btn)
ddi = MDDropDownItem(text= "Select Type")
grid.add_widget(ddi)
if __name__ == __main__ :
ExampleApp().run()
KV 档案:
MDBoxLayout:
MDGridLayout:
id: column_grid
cols: 1
RelativeLayout:
MDDropDownItem:
id: types_dropdownmenu
text: "Select Type"
font_size: 18
size_hint: (0.3, 0.5)
pos_hint: { center_x : 0.2, center_y : 1}
on_release: app.open_menu(self)
MDIconButton:
id: add_col
icon: plus-thick
theme_text_color: Custom
text_color: (0.5, 0.5, 1, 1)
user_font_size: "20sp"
on_release: app.add_column()
```
Sorry for the formatting i guess. I never undertood how to make it work properly...