Custom tkinter button widget

Viewed 38

I am new to software development. I have been busy trying to code a button with different multiline text and different fonts.

This is the closest I have got, with the help of Creating a custom widget in tkinter:

class FrameLabels(Frame):
    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.configure(width=100, height=50, bg='white')

        self.label = Label(self, text="fe", fg='black', bg='white',
                           font=("Calibri", 14, 'bold'))
        self.label.pack()

        self.label = Label(self, text="fef", fg='black', bg='white',
                            font=("Calibri", 12))
        self.label.pack()


class CustomButton(Button):
    def __init__(self, parent):
        Button.__init__(self, parent)
        self.button = FrameLabels(self)
        self.button.pack() 

This is how I am calling the widget in another class:

a = CustomButton(self)
a.grid(row=0, column=0)

With this code, I am indeed getting a frame with different lines of text "within" a button. The problem is that only the border of the custom widget functions as a button. Moreover, it still makes a weird effect when I click on it.

Would someone please help me? I would really appreciate it.

0 Answers
Related