Tkinter, step 2: adapt imports.

This commit is contained in:
Georg Brandl 2008-05-17 18:39:55 +00:00
parent 3302312383
commit 14fc4270da
50 changed files with 136 additions and 133 deletions

View file

@ -8,7 +8,7 @@
__version__ = "0.9"
import Tkinter
import tkinter
# weight/slant
NORMAL = "normal"
@ -65,7 +65,7 @@ class Font:
def __init__(self, root=None, font=None, name=None, exists=False, **options):
if not root:
root = Tkinter._default_root
root = tkinter._default_root
if font:
# get actual settings corresponding to the given font
font = root.tk.splitlist(root.tk.call("font", "actual", font))
@ -79,7 +79,8 @@ class Font:
self.delete_font = False
# confirm font exists
if self.name not in root.tk.call("font", "names"):
raise Tkinter._tkinter.TclError("named font %s does not already exist" % (self.name,))
raise tkinter._tkinter.TclError(
"named font %s does not already exist" % (self.name,))
# if font config info supplied, apply it
if font:
root.tk.call("font", "configure", self.name, *font)
@ -166,13 +167,13 @@ class Font:
def families(root=None):
"Get font families (as a tuple)"
if not root:
root = Tkinter._default_root
root = tkinter._default_root
return root.tk.splitlist(root.tk.call("font", "families"))
def names(root=None):
"Get names of defined fonts (as a tuple)"
if not root:
root = Tkinter._default_root
root = tkinter._default_root
return root.tk.splitlist(root.tk.call("font", "names"))
# --------------------------------------------------------------------
@ -180,7 +181,7 @@ def names(root=None):
if __name__ == "__main__":
root = Tkinter.Tk()
root = tkinter.Tk()
# create a font
f = Font(family="times", size=30, weight=NORMAL)
@ -202,10 +203,10 @@ if __name__ == "__main__":
f = Font(font=("Courier", 20, "bold"))
print(f.measure("hello"), f.metrics("linespace"))
w = Tkinter.Label(root, text="Hello, world", font=f)
w = tkinter.Label(root, text="Hello, world", font=f)
w.pack()
w = Tkinter.Button(root, text="Quit!", command=root.destroy)
w = tkinter.Button(root, text="Quit!", command=root.destroy)
w.pack()
fb = Font(font=w["font"]).copy()
@ -213,4 +214,4 @@ if __name__ == "__main__":
w.config(font=fb)
Tkinter.mainloop()
tkinter.mainloop()