Advertisement
Guest User

Untitled

a guest
Jun 9th, 2021
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.55 KB | None | 0 0
  1. import tkinter as tk
  2.  
  3. root = tk.Tk()
  4.  
  5.  
  6. class MLabel(tk.Canvas):
  7.     def __init__(self, parent, text='Text', fill='black', font=('Calibri', 16), ratio=2/7, bg='#F2F2F2', *args, **kwargs):
  8.         super().__init__(parent, *args, bg=bg, **kwargs)
  9.  
  10.         pady=int(font[1]*ratio)
  11.         self.txtid = self.create_text(0, -pady, text=text, fill=fill, font=font, anchor='nw')
  12.         bbox = self.bbox(self.txtid)
  13.         self.configure(width=bbox[2], height=bbox[3]-pady)
  14.  
  15.  
  16. label = MLabel(root, font=('Calibri', 50))
  17. label.grid()
  18.  
  19. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement