1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
import tkinter as tk
from tkinter import *
import tkinter.font as tkFont
root = Tk()
cnv = Canvas(root)
cnv.pack()
# textes de différentes tailles
cnv.create_text(200, 50, font=tkFont.Font(family="Arial", size=10), text="blabla")
cnv.create_text(200,100, font=tkFont.Font(family="Arial", size=15), text="blibli")
cnv.create_text(200,150, font=tkFont.Font(family="Arial", size=20), text="bloblo")
cnv.create_text(200,200, font=tkFont.Font(family="Arial", size=25), text="blublu")
# récupérer la taille de chaque item "text"
lst = cnv.find("all")
n = 0
while n < len(lst) :
obj = lst[n]
police = cnv.itemcget(obj,"font")
print (police) # mouais ... tk a créé des font1, font2, etc ...
taille = police.cget("size") # OUPS ! AttributeError: 'str' object has no attribute 'cget'
print (taille)
n = n+1
root.mainloop() |
Partager