当前位置: 首页>>代码示例>>Python>>正文


Python Font.measure方法代码示例

本文整理汇总了Python中tkinter.font.Font.measure方法的典型用法代码示例。如果您正苦于以下问题:Python Font.measure方法的具体用法?Python Font.measure怎么用?Python Font.measure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tkinter.font.Font的用法示例。


在下文中一共展示了Font.measure方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: count_lines

# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import measure [as 别名]
    def count_lines(self, s):
        """Count the number of lines in a given text.

        Before calculation, the tab width and line length of the text are
        fetched, so that up-to-date values are used.

        Lines are counted as if the string was wrapped so that lines are never
        over linewidth characters long.

        Tabs are considered tabwidth characters long.
        """
        # Tab width is configurable
        tabwidth = self.editwin.get_tk_tabwidth()

        # Get the Text widget's size
        linewidth = self.editwin.text.winfo_width()
        # Deduct the border and padding
        linewidth -= 2*sum([int(self.editwin.text.cget(opt))
                            for opt in ('border', 'padx')])

        # Get the Text widget's font
        font = Font(self.editwin.text, name=self.editwin.text.cget('font'))
        # Divide the size of the Text widget by the font's width.
        # According to Tk8.5 docs, the Text widget's width is set
        # according to the width of its font's '0' (zero) character,
        # so we will use this as an approximation.
        # see: http://www.tcl.tk/man/tcl8.5/TkCmd/text.htm#M-width
        linewidth //= font.measure('0')

        return count_lines_with_wrapping(s, linewidth, tabwidth)
开发者ID:FFMG,项目名称:myoddweb.piger,代码行数:32,代码来源:squeezer.py

示例2: text_extents

# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import measure [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)
            }
开发者ID:StuxSoftware,项目名称:AnimaFX,代码行数:27,代码来源:text_extents.py

示例3: Scroller

# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import measure [as 别名]
class Scroller(object):
    """
    Scrolls through a solution list.
    """
    def __init__(self, wdw, sols):
        """
        Stores the list of solutions in sols
        and defines the layout of the GUI.
        """
        wdw.title('solutions scroller')
        self.sols = sols
        self.cursor = 0
        self.lbl = Label(wdw, text="solution : ")
        self.lbl.grid(row=0, column=0, sticky=E) 
        self.ent = Entry(wdw)
        self.ent.grid(row=0, column=1, stick=W)
        self.ent.insert(INSERT, "0 of %d" % len(sols))
        self.myft = Font(family="Courier New", size=12, weight="normal")
        self.mlen = self.myft.measure("M")
        lines = sols[0].split('\n')
        self.width = max([len(line) for line in lines])
        self.display = StringVar()
        self.display.set(self.sols[0])
        self.mess = Message(wdw, textvariable=self.display, \
            font=self.myft, width=self.width*self.mlen, background='white')
        self.mess.grid(row=1, column=0, columnspan=2)
        self.btnext = Button(wdw, command=self.next, text='next')
        self.btnext.grid(row=2, column=1, sticky=W+E)
        self.btprev = Button(wdw, command=self.previous, text='previous')
        self.btprev.grid(row=2, column=0, sticky=W+E)

    def show(self):
        """
        Shows the solution at position self.cursor
        in the message widget and updates the entry widget.
        """
        self.display.set(self.sols[self.cursor])
        self.ent.delete(0, END)
        self.ent.insert(INSERT, '%d of %d' % (self.cursor, len(self.sols)))

    def next(self):
        """
        Increases the cursor by one if possible.
        """
        if self.cursor < len(self.sols) - 1:
            self.cursor = self.cursor + 1
        self.show()

    def previous(self):
        """
        Decreases the cursor by one if possible.
        """
        if self.cursor > 0:
            self.cursor = self.cursor - 1
        self.show()
开发者ID:janverschelde,项目名称:PHCpack,代码行数:57,代码来源:dashboard.py

示例4: Make

# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import measure [as 别名]
    def Make(self):
        """ Displays all of this Month's expenses. """

        # If the ExpenseFrame exists, it will be destroyed
        try:
            self.outer.destroy()
        except AttributeError as e:
            if debug: print(e.__class__, ':: ', e)
            else: pass

        # outer is created so the delete button frames can be
        # seperated visually from the expense list frame.
        self.outer = tk.Frame(self)
        self.outer.pack()

        self.Title()

        self.ExpenseFrame = tk.Frame(self.outer)
        self.ExpenseFrame.pack(fill='both')

        # Scrollbar for expense list
        scrollbar = tk.Scrollbar(self.ExpenseFrame)
        scrollbar.pack(side='right', fill='y')

        # Columns for expense list
        dataCols = ['Date', 'Expense Type', 'Cost', 'Notes']

        self.tree = ttk.Treeview(self.ExpenseFrame,
                                 columns=dataCols,
                                 show='headings')

        Exp_Attrs = self.master.Budget.expenses.get()

        # maxWidths is used to store the max width of each column in the
        # TreeView object.
        maxWidths = dict()

        # Loop sets max for each column to 0, so each max has starting value
        for col in dataCols:
            maxWidths[col] = 0

        # Defines the font that the TreeView elements will use
        treeFont = Font(self.ExpenseFrame, 'Times', "12")

        # Inserts each expense into the Treeview object
        for values in Exp_Attrs:
            self.tree.insert('', 'end', values=values, tag='expense')

            # This loop finds the width of the largest string in each column.
            for col, item in zip(dataCols, values):
                stringWidth = treeFont.measure(item)
                if stringWidth > maxWidths[col]:
                    maxWidths[col] = stringWidth

        # This loop serves two functions:
        # 1 - Sets the headings in the expense list.
        #     Without this loop, the headings will not actually show.
        #
        # 2 - Sets the width of each column based on the largest string within
        #     each column.
        for col in dataCols:
            self.tree.heading(col, text=col)
            extra = 100
            MAX = maxWidths[col] + extra
            self.tree.column(col, width=MAX)

        # Sets the font of the TreeView elements
        self.tree.tag_configure('expense', font=treeFont)

        # 'yscroll' option must be set to scrollbar set object
        self.tree['yscroll'] = scrollbar.set

        self.tree.pack(side='left', fill='both')

        # Associates scrollbar with the Treeview object
        scrollbar.config(command=self.tree.yview)

        self.CreateDeleteButton()
开发者ID:bbugyi200,项目名称:Budget,代码行数:80,代码来源:expensedisplay.py

示例5: UITabs

# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import measure [as 别名]

#.........这里部分代码省略.........
        #         swap the last displayed tab with the currently selected
        #         one, to ensure it is displayed. Note this doesn't update
        #         the actual order (in self.tabs), just display state info.
        if self.current in extra:
            last = displayed[-1]
            self.info[self.current]['visible'] = True
            self.info[self.current]['left'] = self.info[last]['left']
            self.info[self.current]['shift'] = self.info[last]['shift']
            self.info[last]['visible'] = False
            del(self.info[last]['left'])
            del(self.info[last]['shift'])
            displayed.remove(last)
            extra.insert(0, last)
            extra.remove(self.current)
            displayed.append(self.current)
        self.overflow_tab = displayed[-1] if extra else None
        self.plus_x = xpos

    def calculate_tabwidth(self):
        "Determine width of a tab, factoring in available space, etc."
        fullwidth = self.winfo_width()
        numtabs = len(self.tabs)
        if numtabs == 0:
            return -1
        tabwidth = int((fullwidth - self.addiconwidth) / numtabs)
        if tabwidth < self.minwidth:
            tabwidth = self.minwidth
        if tabwidth > self.maxwidth:
            tabwidth = self.maxwidth
        return tabwidth

    def tablabel(self, title, width):
        "Truncate any long titles that would not fit within the tab label"
        if self.titlefont.measure(title) <= width:
            return title
        dotwidth = self.titlefont.measure('...')
        while True:
            if self.titlefont.measure(title+'...') <= width:
                return title+'...'
            title = title[:-1]

    def update_mouseover(self, x):
        "Determine if the tab our mouse is over has changed, and adjust if so"
        nowover = self.tabunder(x) if x != -1 else None
        if nowover != self.mouseover:
            self.tooltip_clear()
            self.mouseover = nowover
            self.rebuild()
            if nowover is not None and \
                            self.info[nowover]['tooltip'] is not None:
                self.tooltip_schedule()

    def tabunder(self, x):
        "Identify which tab is at a given position"
        for t in self.tabs:
            if self.info[t]['visible'] and self.info[t]['left'] <= x <\
                                self.info[t]['left'] + self.tabwidth:
                return t
        return None

    def rebuild(self, ev=None):
        """
        Update the display to match the current state of the user interface.
        This actually draws all the pieces of the tabs, indicators, etc. on
        the canvas. We take a brute force approach and recreate everything
        from scratch each time we're called, which happens on any significant
开发者ID:Darriall,项目名称:idle,代码行数:70,代码来源:uitabs.py

示例6: Font

# 需要导入模块: from tkinter.font import Font [as 别名]
# 或者: from tkinter.font.Font import measure [as 别名]
    treeState[col]['selected'] = False if direction else True
    treeState[col]['alternate'] = True if direction else False
    if ttk.Style().theme_use() == 'aque':
        tree.heading(col, state='user1')
        treeState[col]['user1'] = True
    else:
        tree.heading(col, image=upArrow if direction else downArrow)
style = ttk.Style()
from tkinter.font import Font
font_ = Font(name=style.lookup('Heading', 'font'), exists=True)
globals().update(locals())
for col in title:
    name = col
    tree.heading(col, text=name, image=noArrow, anchor='w',
        command=lambda col=col: SortBy(tree, col, False))
    tree.column(col, width=font_.measure(name)+noArrow.width()+5)
font_ = Font(name=style.lookup('Treeview', 'font'), exists=True)
for i in data:
    tree.insert('', 'end', values=' '.join(i))
    for n in i:
        len_ = font_.measure(col+'  ')
        if tree.column(col, 'width') < len_:
            tree.column(col, width=len_)

## Code to do the sorting of the tree contents when clicked on
##proc SortBy {tree col direction} {
##    # Determine currently sorted column and its sort direction
##    foreach c {country capital currency} {
##	set s [$tree heading $c state]
##	if {("selected" in $s || "alternate" in $s) && $col ne $c} {
##	    # Sorted column has changed
开发者ID:zaazbb,项目名称:tkinterdemo,代码行数:33,代码来源:mclist.py


注:本文中的tkinter.font.Font.measure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。