Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Kivy-触摸后添加其他MDFloatingAction按钮_Python_Kivy_Kivy Language - Fatal编程技术网

Python Kivy-触摸后添加其他MDFloatingAction按钮

Python Kivy-触摸后添加其他MDFloatingAction按钮,python,kivy,kivy-language,Python,Kivy,Kivy Language,我试图在单击按钮后添加MDFloatingActionButton小部件,但没有得到它 有人可以帮我解决这个问题 目标是在单击带有图标plus的晶圆厂后创建一个按钮列表 我尝试了多种方式向add_widget()添加代码,但都没有成功 fab.py from kivy.app import App from kivy.uix.widget import Widget from kivy.properties import NumericProperty from kivymd.theming i

我试图在单击按钮后添加MDFloatingActionButton小部件,但没有得到它

有人可以帮我解决这个问题

目标是在单击带有图标plus的晶圆厂后创建一个按钮列表

我尝试了多种方式向
add_widget()
添加代码,但都没有成功

fab.py

from kivy.app import App
from kivy.uix.widget import Widget
from kivy.properties import NumericProperty
from kivymd.theming import ThemeManager
from kivymd.time_picker import MDTimePicker
from kivymd.button import MDFloatingActionButton
from kivy.animation import Animation
from kivy.core.window import Window

Window.clearcolor = (1, 1, 1, 1)

class MDFloatingActionButtonList(MDFloatingActionButton):
    angle = NumericProperty(0)
    def on_touch_up(self, touch):
        if self.collide_point(*touch.pos):
            if self.angle == 0:
                self.angle += 45
                #MDFloatingActionButton.add_widget()
            else:
                self.angle -= 45

class Fab(App):
    theme_cls = ThemeManager()
    def build(self):
        return MDFloatingActionButtonList()    

Fab().run()
fab.kv

<MDFloatingActionButtonList>:
    canvas.before:                                                                                                                                             
        PushMatrix                                                                                                                                             
        Rotate:                                                                                                                                                
            angle: self.angle                                                                                                                                  
            axis: (0, 0, 1)                                                                                                                                    
            origin: self.center                                                                                                                                
    canvas.after:                                                                                                                                              
        PopMatrix
    MDFloatingActionButton:
        id: float_act_btn
        icon: 'plus'
        opposite_colors: True
        elevation_normal: 8
        pos_hint: {'center_x': 0.5, 'center_y': 0.2}
:
在以下情况之前:
推矩阵
轮换:
角度:self.angle
轴:(0,0,1)
来源:自我中心
在下列情况之后:
流行音乐
MDFloatingActionButton:
id:float\u act\u btn
图标:“plus”
相反颜色:真
正常高度:8
位置提示:{'center_x':0.5,'center_y':0.2}
结果:

目标例如:


哦,天哪,这是一个艰难的时刻。KivyMD项目的文档记录很差,尽管设计非常漂亮

好的,下面是一个可能的例子:

from kivy.app import App
from kivy.core.window import Window
from kivy.uix.boxlayout import BoxLayout

from kivymd.button import MDFloatingActionButton
from kivymd.menu import MDDropdownMenu
from kivymd.theming import ThemeManager

Window.clearcolor = (1, 1, 1, 1)

menu_items = [
    {'viewclass': 'MDFloatingActionButton',
     'text': 'Example',
     'on_press': lambda: print("Hello")},
    {'viewclass': 'MDFloatingActionButton',
     'text': 'Example'},
    {'viewclass': 'MDFloatingActionButton',
     'text': 'Example'},
    {'viewclass': 'MDFloatingActionButton',
     'text': 'Example item'},
    {'viewclass': 'MDFloatingActionButton',
     'text': 'Example'},
    {'viewclass': 'MDFloatingActionButton',
     'text': 'Example'},
    {'viewclass': 'MDFloatingActionButton',
     'text': 'Example'},
]


class Fab(App):
    theme_cls = ThemeManager()
    layout = BoxLayout()
    md = MDDropdownMenu(items=menu_items)

    def build(self):
        button = MDFloatingActionButton()
        self.layout.add_widget(button)
        button.bind(on_press=lambda x: self.md.open(button))
        return self.layout


Fab().run()

另一种方法是手动将按钮添加到窗口中。但接下来您将不得不处理dissmiss(我没有实现它):


你为什么不试试这个

MDFloatingActionButtonSpeedDial

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
Screen:

    MDFloatingActionButtonSpeedDial:
        data: app.data
        root_button_anim: True
'''


class Example(MDApp):
     data = {
           'language-python': 'Python',
           'language-php': 'PHP',
           'language-cpp': 'C++',
      }

     def build(self):
           return Builder.load_string(KV)


Example().run()
以下是输出:

from kivy.lang import Builder

from kivymd.app import MDApp

KV = '''
Screen:

    MDFloatingActionButtonSpeedDial:
        data: app.data
        root_button_anim: True
'''


class Example(MDApp):
     data = {
           'language-python': 'Python',
           'language-php': 'PHP',
           'language-cpp': 'C++',
      }

     def build(self):
           return Builder.load_string(KV)


Example().run()