Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import tkinter as tk
- root = tk.Tk()
- class MLabel(tk.Canvas):
- def __init__(self, parent, text='Text', fill='black', font=('Calibri', 16), ratio=2/7, bg='#F2F2F2', *args, **kwargs):
- super().__init__(parent, *args, bg=bg, **kwargs)
- pady=int(font[1]*ratio)
- self.txtid = self.create_text(0, -pady, text=text, fill=fill, font=font, anchor='nw')
- bbox = self.bbox(self.txtid)
- self.configure(width=bbox[2], height=bbox[3]-pady)
- label = MLabel(root, font=('Calibri', 50))
- label.grid()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement