0

I would like to create dynamic styles for labels that can have 4 background options, but the style function does not accept lambda, or functions in general, how could I dynamically switch the unique styles of my layout

Create styles

        self.style.configure('Club.TLabel',background='green') # Club card color 
        self.style.configure('Diamond.TLabel',background='blue') # Diamond card color 
        self.style.configure('Heart.TLabel',background='red') # Heart card color

Try to add a config with dynamic style

        def handleCardStyle(card):
            if 'c' in card:
                return 'Club.TLabel'
            elif 'd' in card:
                return 'Club.TLabel'
            elif 'h' in card:
                return 'Diamond.TLabel'

        self.firstHeroCard = Label(self.tableContainner,text='Ac',anchor=CENTER)
        self.firstHeroCard.configure(style=lambda: handleCardStyle('Ac'))
        self.firstHeroCard.place(relx=0.5,rely=1,relwidth=0.1,relheight=0.2,anchor=SE) 
Hemanth Kumar
  • 2,728
  • 1
  • 4
  • 19
Collaxd
  • 425
  • 3
  • 12

0 Answers0