Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_fontmeasure.py
- import Tkinter as tk
- import tkFont
- root = tk.Tk()
- canvas = tk.Canvas(root, width=300, height=200)
- canvas.pack()
- (x,y) = (5,5)
- text = "Hello Python World"
- fonts = []
- for (family,size) in [("times",12),("times",24)]:
- font = tkFont.Font(family=family, size=size)
- (w,h) = (font.measure(text),font.metrics("linespace"))
- print "%s %s: (%s,%s)" % (family,size,w,h)
- canvas.create_rectangle(x,y,x+w,y+h)
- canvas.create_text(x,y,text=text,font=font,anchor=tk.NW)
- fonts.append(font) # save object from garbage collecting
- y += h+5
- tk.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement