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


Python font.Font类代码示例

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


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

示例1: count_lines

    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,代码行数:30,代码来源:squeezer.py

示例2: SyntexHighlight

 def SyntexHighlight(self, event=None):
     from tkinter.font import Font
     for tag in self.tag_names():
         self.tag_delete(tag)
     self.mark_set("range_start", "1.0")
     data = self._get_value()
     self.tag_configure("Token.Comment", foreground="#F00")
     bolder = Font(family=self.app.cnf['font'][0])
     bolder.config(size=self.app.cnf['font'][1]-2)
     bolder.config(weight="bold")
     for token, content in lex(data, PythonLexer()):
         self.mark_set("range_end", "range_start + %dc" % len(content))
         self.tag_add(str(token), "range_start", "range_end")
         self.mark_set("range_start", "range_end")
     self.tag_config("Token.Comment.Single", foreground="#F00")
     self.tag_config("Token.Literal.String.Doc", foreground="#F00")
     for tag in self.tag_names():
         if 'Token.Keyword' == tag:
             self.tag_config(tag, foreground="#008", font=bolder)
         elif 'Token.Keyword.Namespace' == tag:
             self.tag_config(tag, foreground="#00F", font=bolder)
         elif 'Token.Name.Class' in tag:
             self.tag_config(tag, foreground="#F30", background='#AFA')
         elif 'Token.Name.Function' in tag:
             self.tag_config(tag, foreground="#A3A", background='#FFA')
         elif 'Token.Literal' in tag:
             self.tag_config(tag, foreground="#6A0")
         elif 'Token.Operator' in tag:
             self.tag_config(tag, foreground="#A3A")
     print(self.tag_names())
开发者ID:soma0sd,项目名称:python-study,代码行数:30,代码来源:main.py

示例3: text_extents

        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,代码行数:25,代码来源:text_extents.py

示例4: initialize

    def initialize(self):
        #Create the menubar
        self.menubar=Menu(self)
        menu=Menu(self.menubar,tearoff=0)
        self.menubar.add_cascade(label="File",menu=menu)
        menu.add_command(label="Open",command=self.openfile)
        #menu.add_command(label="Exit")
        menu=Menu(self.menubar,tearoff=0)
        self.menubar.add_cascade(label="Tools",menu=menu)
        menu.add_command(label="Class",command=self.classwindow)
        menu.add_command(label="Hilbert",command=self.hilbertwindow)
        menu.add_command(label="Entropy",command=self.entropywindow)
        menu.add_command(label="Gradient",command=self.gradientwindow)
        self.master.config(menu=self.menubar)

        #Configure grid layout
        self.columnconfigure(0,pad=5)
        self.columnconfigure(1,pad=5)
        self.columnconfigure(2,pad=5)
        self.rowconfigure(0,pad=5)
        self.rowconfigure(0,pad=5)

        #Add canvas to plot points from converted hex values
        self.plotcanvas=Canvas(self,width=256,height=256)
        self.plotcanvas.configure(background='black')
        self.plotcanvas.grid(row=0,column=0)

        #Add listbox to hold the current group of hexvalues
        listframe=Frame(self)
        hexscroll=Scrollbar(listframe,orient=VERTICAL)
        hexbox_font = Font(size=8)
        hexbox_font.config(family={"posix": "Monospace","nt": "Courier New"})
        self.hexbox=Listbox(listframe,width=75,height=20,font=hexbox_font,yscrollcommand=hexscroll.set,selectmode=EXTENDED)
        hexscroll.config(command=self.hexbox.yview)
        hexscroll.pack(side=RIGHT,fill=Y)
        self.hexbox.pack(side=LEFT)
        listframe.grid(row=0,column=1)

        #Add slider for location in hex lines and size of window of hex values
        commandframe=Frame(self)
        playframe=Frame(commandframe)
        windowframe=Frame(commandframe)
        self.playslider=Scale(playframe,command=self.playslider_moved)
        self.playslider.configure(from_=0,to=100)
        self.playslider.configure(orient=HORIZONTAL)
        self.playslider.pack(side=BOTTOM)
        hexaddress=gethexaddress(int(self.playslider.get()))
        self.currhexaddress=Label(playframe,width=20,text=hexaddress)
        self.currhexaddress.pack(side=TOP)
        self.curroffset=Label(windowframe,text=self.hexaddressoffset)
        self.curroffset.pack(side=TOP)
        self.windowslider=Scale(windowframe,command=self.windowslider_moved)
        self.windowslider.configure(from_=100,to=600,orient=HORIZONTAL)
        self.windowslider.pack(side=TOP)
        self.windowslider.set(self.hexaddressoffset)
        playframe.pack(side=LEFT)
        windowframe.pack(side=RIGHT)
        commandframe.grid(row=1,columnspan=2)

        self.pack()
开发者ID:lgraham076,项目名称:DeviceDisassemblyVisualizer,代码行数:60,代码来源:hexvisgui.py

示例5: adjust_fonts

 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)
开发者ID:tajfutas,项目名称:tajf,代码行数:35,代码来源:infopanel.py

示例6: overstrike

 def overstrike(self, *args):
     """Toggles overstrike for selected text."""
     try:
         current_tags = self.text.tag_names("sel.first")
         if "overstrike" in current_tags:
             self.text.tag_remove("overstrike", "sel.first", "sel.last")
         else:
             self.text.tag_add("overstrike", "sel.first", "sel.last")
             overstrike_font = Font(self.text, self.text.cget("font"))
             overstrike_font.configure(overstrike=1)
             self.text.tag_configure("overstrike", font=overstrike_font)
     except TclError:
         pass
开发者ID:Drax-il,项目名称:TextEditor,代码行数:13,代码来源:TextEditor.py

示例7: underline

 def underline(self, *args):
     """Toggles underline for selected text."""
     try:
         current_tags = self.text.tag_names("sel.first")
         if "underline" in current_tags:
             self.text.tag_remove("underline", "sel.first", "sel.last")
         else:
             self.text.tag_add("underline", "sel.first", "sel.last")
             underline_font = Font(self.text, self.text.cget("font"))
             underline_font.configure(underline=1)
             self.text.tag_configure("underline", font=underline_font)
     except TclError:
         pass
开发者ID:Drax-il,项目名称:TextEditor,代码行数:13,代码来源:TextEditor.py

示例8: italic

 def italic(self, *args):
     """Toggles italic for selected text."""
     try:
         current_tags = self.text.tag_names("sel.first")
         if "italic" in current_tags:
             self.text.tag_remove("italic", "sel.first", "sel.last")
         else:
             self.text.tag_add("italic", "sel.first", "sel.last")
             italic_font = Font(self.text, self.text.cget("font"))
             italic_font.configure(slant="italic")
             self.text.tag_configure("italic", font=italic_font)
     except TclError:
         pass
开发者ID:Drax-il,项目名称:TextEditor,代码行数:13,代码来源:TextEditor.py

示例9: bold

 def bold(self, *args):
     """Toggles bold for selected text."""
     try:
         current_tags = self.text.tag_names("sel.first")
         if "bold" in current_tags:
             self.text.tag_remove("bold", "sel.first", "sel.last")
         else:
             self.text.tag_add("bold", "sel.first", "sel.last")
             bold_font = Font(self.text, self.text.cget("font"))
             bold_font.configure(weight="bold")
             self.text.tag_configure("bold", font=bold_font)
     except TclError:
         pass
开发者ID:Drax-il,项目名称:TextEditor,代码行数:13,代码来源:TextEditor.py

示例10: GetFont

    def GetFont(self, root, configType, section):
        """Retrieve a font from configuration (font, font-size, font-bold)
        Intercept the special value 'TkFixedFont' and substitute
        the actual font, factoring in some tweaks if needed for
        appearance sakes.

        The 'root' parameter can normally be any valid Tkinter widget.

        Return a tuple (family, size, weight) suitable for passing
        to tkinter.Font
        """
        family = self.GetOption(configType, section, 'font', default='courier')
        size = self.GetOption(configType, section, 'font-size', type='int',
                              default='10')
        bold = self.GetOption(configType, section, 'font-bold', default=0,
                              type='bool')
        if (family == 'TkFixedFont'):
            f = Font(name='TkFixedFont', exists=True, root=root)
            actualFont = Font.actual(f)
            family = actualFont['family']
            size = actualFont['size']
            if size <= 0:
                size = 10  # if font in pixels, ignore actual size
            bold = actualFont['weight'] == 'bold'
        return (family, size, 'bold' if bold else 'normal')
开发者ID:1st1,项目名称:cpython,代码行数:25,代码来源:config.py

示例11: __init__

 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)
开发者ID:janverschelde,项目名称:PHCpack,代码行数:26,代码来源:dashboard.py

示例12: _init_fonts

    def _init_fonts(self, root):
        # See: <http://www.astro.washington.edu/owen/ROTKFolklore.html>
        self._sysfont = Font(font=Button()["font"])
        root.option_add("*Font", self._sysfont)

        # TWhat's our font size (default=same as sysfont)
        self._size = IntVar(root)
        self._size.set(self._sysfont.cget("size"))

        self._boldfont = Font(family="helvetica", weight="bold", size=self._size.get())
        self._font = Font(family="helvetica", size=self._size.get())
        if self._size.get() < 0:
            big = self._size.get() - 2
        else:
            big = self._size.get() + 2
        self._bigfont = Font(family="helvetica", weight="bold", size=big)
开发者ID:BRISATECH,项目名称:ResumeManagementTool,代码行数:16,代码来源:drt_glue_demo.py

示例13: GetFont

    def GetFont(self, root, configType, section):
        """Retrieve a font from configuration (font, font-size, font-bold)
        Intercept the special value 'TkFixedFont' and substitute
        the actual font, factoring in some tweaks if needed for
        appearance sakes.

        The 'root' parameter can normally be any valid Tkinter widget.

        Return a tuple (family, size, weight) suitable for passing
        to tkinter.Font
        """
        family = self.GetOption(configType, section, "font", default="courier")
        size = self.GetOption(configType, section, "font-size", type="int", default="10")
        bold = self.GetOption(configType, section, "font-bold", default=0, type="bool")
        if family == "TkFixedFont":
            if TkVersion < 8.5:
                family = "Courier"
            else:
                f = Font(name="TkFixedFont", exists=True, root=root)
                actualFont = Font.actual(f)
                family = actualFont["family"]
                size = actualFont["size"]
                if size < 0:
                    size = 10  # if font in pixels, ignore actual size
                bold = actualFont["weight"] == "bold"
        return (family, size, "bold" if bold else "normal")
开发者ID:roseman,项目名称:idle,代码行数:26,代码来源:configHandler.py

示例14: Scroller

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,代码行数:55,代码来源:dashboard.py

示例15: __init__

 def __init__(self, master):
     BaseDiablog.__init__(self, master, "Preferences", exit_on_esc=True)
     self.startup_check = Config.config["startup_check"]
     self.general_label = ttk.Label(self.body,
                                    text="General")
     font = Font(self.general_label, self.general_label.cget("font"))
     font.configure(underline=True)
     self.general_label.configure(font=font)
     self.config_frame = ttk.Frame(self)
     self.startup_check_checkbtn = ttk.Checkbutton(self.config_frame,
                                                   text="Check for update at launch",
                                                   variable=PreferencesDialog.startup_check.raw_klass(self),
                                                   command=self._startup_check_clicked)
     self.buttons_frame = ttk.Frame(self)
     self.close_button = ttk.Button(self.buttons_frame,
                                    text="Close",
                                    command=self.destroy)
     options = dict(padx=5, pady=5)
     self.general_label.pack(side=LEFT, **options)
     self.config_frame.pack(fill=BOTH, expand=True, **options)
     self.startup_check_checkbtn.pack(side=LEFT, **options)
     self.buttons_frame.pack(side=BOTTOM, fill=BOTH, expand=True, **options)
     self.close_button.pack(side=RIGHT, expand=False)
开发者ID:Arzaroth,项目名称:CelestiaSunrise,代码行数:23,代码来源:dialogs.py


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