本文整理汇总了Python中tkinter.font.Font.metrics方法的典型用法代码示例。如果您正苦于以下问题:Python Font.metrics方法的具体用法?Python Font.metrics怎么用?Python Font.metrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.font.Font
的用法示例。
在下文中一共展示了Font.metrics方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: adjust_fonts
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import metrics [as 别名]
def adjust_fonts(self, event):
new_font = Font(**self.fonts['normal'].configure())
size = orig_size = new_font['size']
desired_total_height = event.height
orig_row_height = new_font.metrics('linespace')
orig_row_height += self.LS_EXTRA
orig_total_height = self.N_ROWS * orig_row_height
if orig_total_height < desired_total_height:
a, compfname, final_neg_adjust = 1, '__gt__', True
elif orig_total_height > desired_total_height:
a, compfname, final_neg_adjust = -1, '__lt__', False
else:
return
prev_total_height = orig_total_height
while True:
if a < 0 and size <= self.MIN_FONT_SIZE:
size = self.MIN_FONT_SIZE
break
size += a
new_font.configure(size=size)
new_row_height = new_font.metrics('linespace')
new_row_height += self.LS_EXTRA
new_total_height = self.N_ROWS * new_row_height
if new_total_height == prev_total_height:
size -= a
break
compf = getattr(new_total_height, compfname)
if compf(desired_total_height):
if final_neg_adjust and size > self.MIN_FONT_SIZE:
size -= a
break
prev_total_height = new_total_height
if size != orig_size:
self.fonts['normal'].configure(size=size)
self.fonts['bold'].configure(size=size)
示例2: text_extents
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import metrics [as 别名]
def text_extents(self, style, text):
"""
The text extents are calculated using tkinter.Font
"""
with InternalWindow() as window:
font_type = ""
if style["bold"]:
font_type += "bold"
if style["italic"]:
if len(font_type) > 0:
font_type += " "
font_type += "italic"
# Create the new font object.
font = Font(window, (style["font"], -int(style["size"]*FONT_SCALING), font_type))
# Query the data
width = font.measure(text)
metrics = font.metrics()
return {
"width": width / float(FONT_SCALING),
"height": metrics["linespace"] / float(FONT_SCALING),
"ascent": metrics["ascent"] / float(FONT_SCALING),
"descent": metrics["descent"] / float(FONT_SCALING)
}
示例3:
# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import metrics [as 别名]
statusBar_lab.pack(side='left', padx=2, expand='yes', fill='both')
if root._windowingsystem != 'aqua':
foo = ttk.Sizegrip(statusBar)
foo.pack(side='left', padx=2)
statusBar.pack(side='bottom', fill='x', pady=2)
##set textheight 30
##catch {
## set textheight [expr {
## ([winfo screenheight .] * 0.7) /
## [font metrics mainFont -displayof . -linespace]
## }]
##}
textheight = 30
try:
textheight = root.winfo_screenheight() * 0.7 / mainFont.metrics('linespace', displayof='.')
except:
pass
##ttk::frame .textFrame
##scrollbar .s -orient vertical -command {.t yview} -takefocus 1
##pack .s -in .textFrame -side right -fill y
##text .t -yscrollcommand {.s set} -wrap word -width 70 -height $textheight \
## -font mainFont -setgrid 1 -highlightthickness 0 \
## -padx 4 -pady 2 -takefocus 0
##pack .t -in .textFrame -expand y -fill both -padx 1
##pack .textFrame -expand yes -fill both
##if {[tk windowingsystem] eq "aqua"} {
## pack configure .statusBar.lab -padx {10 18} -pady {4 6}
## pack configure .statusBar -pady 0
## .t configure -padx 10 -pady 0