kivymd / KivyMD

KivyMD is a collection of Material Design compliant widgets for use with Kivy, a framework for cross-platform, touch-enabled graphical applications. https://youtube.com/c/KivyMD https://twitter.com/KivyMD https://habr.com/ru/users/kivymd https://stackoverflow.com/tags/kivymd
https://kivymd.readthedocs.io
MIT License
2.14k stars 655 forks source link

Button style changes with text change #1661

Open RobertFlatt opened 3 months ago

RobertFlatt commented 3 months ago

Description of the Bug

In an MDDialog when changing MDButton text, the button style unexpectedly also changes, in case from 'text' to 'elevated'.

Code and Logs

from kivy.lang import Builder
from kivy.uix.widget import Widget

from kivymd.app import MDApp
from kivymd.uix.button import MDButton, MDButtonText
from kivymd.uix.dialog import (
    MDDialog,
    MDDialogIcon,
    MDDialogHeadlineText,
    MDDialogSupportingText,
    MDDialogButtonContainer,
    MDDialogContentContainer,
)
from kivymd.uix.divider import MDDivider
from kivymd.uix.list import (
    MDListItem,
    MDListItemLeadingIcon,
    MDListItemSupportingText,
)

KV = '''
MDScreen:
    md_bg_color: self.theme_cls.backgroundColor

    MDButton:
        pos_hint: {'center_x': .5, 'center_y': .5}
        on_release: app.show_alert_dialog()

        MDButtonText:
            text: "Show dialog"
'''

class Example(MDApp):
    def build(self):
        return Builder.load_string(KV)

    def show_alert_dialog(self):
        self.left_text = MDButtonText(text="Change Text")
        self.right_text = MDButtonText(text="Disabled")

        MDDialog(
            # -----------------------Headline text-------------------------
            MDDialogHeadlineText(
                text="Button Text Test",
            ),
            # -----------------------Supporting text-----------------------
            MDDialogSupportingText(
                text="Click left button to change text on both buttons.\n\n"
                "Issue: left button style changes from text to elevated."
            ),
            # -----------------------Custom content------------------------
            MDDialogContentContainer(
            ),
            # ---------------------Button container------------------------
            MDDialogButtonContainer(
                Widget(),
                MDButton(
                    self.left_text,
                    style="text",
                    on_release=self.change_text
                ),
                MDButton(
                    self.right_text,
                    style="text",
                    disabled = True),
                spacing="8dp",
            ),
            # -------------------------------------------------------------
        ).open()

    def change_text(self, button):
        self.left_text.text = 'New Text'
        self.right_text.text = 'New Text'

Example().run()

Screenshots

See before click left button and after click left button screenshots attached below.

Versions