我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用tkinter.font.nametofont()。
def body(self, master): ttk.Style().configure("White.TLabel", background="white") ttk.Label(master, image=self.logo, justify="center", style="White.TLabel").pack(pady=10) title = font.Font(family=font.nametofont("TkDefaultFont").cget("family"), size=15, weight="bold") ttk.Label(master, text=(self.program_title, self.version), font=title, justify="center", style="White.TLabel").pack() ttk.Label(master, text=self.description, wraplength=230, justify="center", style="White.TLabel").pack() ttk.Label(master, text=self.copyright_text, justify="center", style="White.TLabel").pack() link = pk.Hyperlink(master, text="Visit the project on GitHub", link="https://github.com/DeflatedPickle/Quiver") link.configure(background="white", justify="center") link.pack(pady=3) link._font.configure(size=10)
def __init__(self, master): self.master = master master.title("StochOPy Viewer") master.protocol("WM_DELETE_WINDOW", self.close_window) master.geometry("900x600") master.minsize(900, 600) master.maxsize(900, 600) default_font = font.nametofont("TkDefaultFont") default_font.configure(family = "Helvetica", size = 9) master.option_add("*Font", default_font) self.define_variables() self.trace_variables() self.init_variables() self.menubar() self.frame1() self.frame2() self.footer() self.select_widget(self.solver_name.get())
def __init__(self, master, **kw): super().__init__(master) # self.grid_propagate(0) # self.columnconfigure(0, weight=1) # self.rowconfigure(0, weight=1) self.var = kw.get('variable', IntVar()) kw['variable'] = self.var kw['from_'] = ConfidenceLevel.Low.value kw['to'] = ConfidenceLevel.VeryHigh.value # kw['command'] = self.scale_change kw['orient'] = HORIZONTAL self.lbl_scale = Label(self) self.scale = Scale(self, **kw) self.scale_font = tkfont.nametofont(Style().lookup('TLabel', 'font')).copy() self.scale_font.config(weight=tkfont.BOLD, size=9) self.lbl_scale.config(font=self.scale_font, width=3, anchor=CENTER) self.var.trace_variable('w', lambda a, b, c: self.scale_change()) self.scale.grid(row=0, column=0, sticky='ns') self.lbl_scale.grid(row=0, column=1, sticky='ns', padx=(3, 0))
def __init__(self, master, text, background=None, font=None, familiy=None, size=None, underline=True, visited_fg = "#551A8B", normal_fg = "#0000EE", visited=False, action=None): self._visited_fg = visited_fg self._normal_fg = normal_fg if visited: fg = self._visited_fg else: fg = self._normal_fg if font is None: default_font = nametofont("TkDefaultFont") family = default_font.cget("family") if size is None: size = default_font.cget("size") font = Font(family=family, size=size, underline=underline) Label.__init__(self, master, text=text, fg=fg, cursor="hand2", font=font) if background is None: background = get_background_of_widget(master) self.configure(background=background) self._visited = visited self._action = action self.bind("<Button-1>", self._on_click)
def body(self, master): text = tk.Text(master, relief="flat", wrap="word", width=0, height=0) text.pack(side="left", fill="both", expand=True) text.tag_configure("header", justify="center", font=(font.nametofont("TkDefaultFont").cget("family"), 12, "bold")) text.tag_configure("hyperlink") scrollbar = ttk.Scrollbar(master, orient="vertical", command=text.yview) scrollbar.pack(side="right", fill="y") text.insert("end", "Libraries:\n", "header") text.insert("end", """- Fredrik Lundh for Tkinter. - Alex Clark for Pillow. - okdana for jsonesque. - twoolie for NBT.\n\n""") text.insert("end", "Programs:\n", "header") text.insert("end", """- MightyPork for ResourcePack Workbench. - dotPDN, LLC for Paint.NET. - JetBrains for PyCharm. - Mojang for Minecraft.\n\n""") text.insert("end", "Other:\n", "header") text.insert("end", """- Hartmut Goebel, Martin Zibricky, David Cortesi and David Vierra for PyInstaller. - GitHub for hosting the code. - Bryan Oakley on StackOverflow for occasional indirect help with code.""") text.configure(state="disabled", yscrollcommand=scrollbar.set)
def test_font_eq(self): fontname = "TkDefaultFont" try: f = font.Font(name=fontname, exists=True) except tkinter._tkinter.TclError: f = font.Font(name=fontname, exists=False) font1 = font.nametofont(fontname) font2 = font.nametofont(fontname) self.assertIsNot(font1, font2) self.assertEqual(font1, font2) self.assertNotEqual(font1, font1.copy()) self.assertNotEqual(font1, 0)