def __init__(self, root=None, font=None, name=None, exists=False, **options): if root is None: root = tkinter._get_default_root('use font') tk = getattr(root, 'tk', root) if font: # get actual settings corresponding to the given font font = tk.splitlist(tk.call("font", "actual", font)) else: font = self._set(options) if not name: name = "font" + str(next(self.counter)) self.name = name if exists: self.delete_font = False # confirm font exists if self.name not in tk.splitlist(tk.call("font", "names")): raise tkinter._tkinter.TclError( "named font %s does not already exist" % (self.name,)) # if font config info supplied, apply it if font: tk.call("font", "configure", self.name, *font) else: # create new font (raises TclError if the font exists) tk.call("font", "create", self.name, *font) self.delete_font = True self._tk = tk self._split = tk.splitlist self._call = tk.call
def families(root=None, displayof=None): "Get font families (as a tuple)" if root is None: root = tkinter._get_default_root('use font.families()') args = () if displayof: args = ('-displayof', displayof) return root.tk.splitlist(root.tk.call("font", "families", *args))
def __init__(self, parent, title = None): '''Initialize a dialog. Arguments: parent -- a parent window (the application window) title -- the dialog title ''' master = parent if not master: master = _get_default_root('create dialog window') Toplevel.__init__(self, master) self.withdraw() # remain invisible for now # If the parent is not viewable, don't # make the child transient, or else it # would be opened withdrawn if parent is not None and parent.winfo_viewable(): self.transient(parent) if title: self.title(title) _setup_dialog(self) self.parent = parent self.result = None body = Frame(self) self.initial_focus = self.body(body) body.pack(padx=5, pady=5) self.buttonbox() if not self.initial_focus: self.initial_focus = self self.protocol("WM_DELETE_WINDOW", self.cancel) if parent is not None: self.geometry("+%d+%d" % (parent.winfo_rootx()+50, parent.winfo_rooty()+50)) self.deiconify() # become visible now self.initial_focus.focus_set() # wait for window to appear on screen before calling grab_set self.wait_visibility() self.grab_set() self.wait_window(self)
def names(root=None): "Get names of defined fonts (as a tuple)" if root is None: root = tkinter._get_default_root('use font.names()') return root.tk.splitlist(root.tk.call("font", "names"))