Harsh Gupta
Harsh Gupta

Reputation: 13

Why height parameter is not working in tb.Label Widget?

I am using tb.Lable from ttkbootstarp but i am not able use height, bd attribute

The error ->

 File "C:\Program Files\Python311\Lib\tkinter\__init__.py", line 1692, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: unknown option "-height"

This is my code ->

from tkinter import *
import ttkbootstrap as tb

class Root(tb.Window):
    def __init__(self):
        super().__init__(themename='superhero')

        self.frame = Frame(self.canvas)
        self.frame.grid(row=0, column=0, sticky="nsew")
        Slot(self.frame)


class Slot(tb.Label):
    SlotList = [] 

    def __init__(self, master=None):
        super().__init__(master)
        Slot.SlotList.append(self)
        self.config(width=40, height=20, bd=1, relief="solid", bg="white")
        self.grid(padx=30, pady=30)

if __name__ == '__main__':
    App = Root()
    App.mainloop()
`

I have tried too much to debug it but it is not working, the problem might be with tb.Lable as i remove tb. it is working properly but i want to use it with tb.Lable

Upvotes: 0

Views: 91

Answers (1)

toyota Supra
toyota Supra

Reputation: 4560

Why height parameter is not working in tb.Label Widget?

but it is not working, the problem might be with tb.Lable as i remove tb. it is working properly but i want to use it with tb.Lable

The problem can be fixed.

  • Add Label in def __init__(self)
  • Remove parameter self.frame in Slot() callable. And add fontsize.

Snippet:

class Root(tb.Window):

        def __init__(self):
            super().__init__(themename='superhero')
    
            self.frame = Frame(self)
            self.frame.grid(row=0, column=0, sticky="nsew")
    
            tb.Label(self, text='python is great', font=("Helvetica", 18)).grid()
            Slot()
    

Screenshot:

enter image description here

Upvotes: -1

Related Questions