2021年3月17日星期三

KivyMD changing Button Color of other Button if one Button is clicked

So I basically want to make a up and downvote system. If I click and unclick a Button it changes the color. The Problem: I need to change the color of the other Button aswell. For example if I upvote the UpButton is green. But if I change my mind about the post and would want to downvote the UpVote Button is still Green. Now I have two colored Buttons. I already tried it with a global variable but this isn't working because it would change the behavior of any widget rooted and not only the one I clicked on. Please help.

class UpButton(MDIconButton):      def __init__(self, **kwargs):          super(UpButton, self).__init__(**kwargs)          self.pos_hint = {"center_x": 0.9, "center_y": .75}          self.icon = 'chevron-up'          self.i = 0        def on_release(self):          self.i += 1          if self.i % 2:              self.theme_text_color = "Custom"              self.text_color = 0.5, 1, 0.5, 1          else:              self.theme_text_color = "Secondary"    class DownButton(MDIconButton):      def __init__(self, **kwargs):          super(DownButton, self).__init__(**kwargs)          self.pos_hint = {"center_x": 0.9, "center_y": .25}          self.icon = 'chevron-down'          self.i = 0        def on_release(self):          self.i += 1          if self.i % 2:              self.theme_text_color="Custom"              self.text_color = 1, 0.5, 0.5, 1            else:              self.theme_text_color = "Secondary"  
https://stackoverflow.com/questions/66683400/kivymd-changing-button-color-of-other-button-if-one-button-is-clicked March 18, 2021 at 09:05AM

没有评论:

发表评论