def test_eq(self):
font1 = font.Font(root=self.root, name=fontname, exists=True)
font2 = font.Font(root=self.root, name=fontname, exists=True)
self.assertIsNot(font1, font2)
self.assertEqual(font1, font2)
self.assertNotEqual(font1, font1.copy())
self.assertNotEqual(font1, 0)
python类Font()的实例源码
def setUpClass(cls):
AbstractTkTest.setUpClass.__func__(cls)
try:
cls.font = font.Font(root=cls.root, name=fontname, exists=True)
except tkinter.TclError:
cls.font = font.Font(root=cls.root, name=fontname, exists=False)
def test_eq(self):
font1 = font.Font(root=self.root, name=fontname, exists=True)
font2 = font.Font(root=self.root, name=fontname, exists=True)
self.assertIsNot(font1, font2)
self.assertEqual(font1, font2)
self.assertNotEqual(font1, font1.copy())
self.assertNotEqual(font1, 0)
def _load_browse_data(self):
self.data = self._get_current_browse_list()
self.pathLabel['text'] = "> " + self.dir_browser.get_friendly_path_name(" + ")
self.tree.delete(*self.tree.get_children())
# add data to the tree
self.tree_index = dict()
for idx in range(len(self.dataCols)):
self.tree.column(self.dataCols[idx], width=10)
for item in self.data:
index = self.tree.insert('', 'end', values=item[1:])
self.tree_index[index] = item
for idx in range(len(self.dataCols)):
iwidth = Font().measure(item[idx + 1]) + 10
if self.tree.column(self.dataCols[idx], 'width') < iwidth:
self.tree.column(self.dataCols[idx], width=iwidth)
def Title():
# Title Setting Start.
logoBack = Label(root, bg = "white")
logoBack.place(width = 1000, height = 85)
logoLine1 = Label(root, bg="black")
logoLine1.place(x=180, y=20, width=170, height=10)
logoLine2 = Label(root, bg="black")
logoLine2.place(x=180, y=40, width=170, height=10)
logoLine3 = Label(root, bg="black")
logoLine3.place(x=180, y=60, width=170, height=10)
logoLine4 = Label(root, bg="black")
logoLine4.place(x=700, y=20, width=170, height=10)
logoLine5 = Label(root, bg="black")
logoLine5.place(x=700, y=40, width=170, height=10)
logoLine6 = Label(root, bg="black")
logoLine6.place(x=700, y=60, width=170, height=10)
logo = Label(root, image = logoImage, bg = 'white')
logo.place(x=0, y=0)
star = Label(root, image = starImage, bg = 'white')
star.place(x=890, y=0)
fontemp = font.Font(root, size = 40, weight = 'bold', slant = 'italic')
title = Label(root, font = fontemp, text="BOX OFFICE", bg = "white")
title.place(x=360, y=10)
# Title Setting End.
# BoxOffice==================================
def BoxOfficeMenu():
global list_boxOffice, m1_ListBox, m2_ListBox, m3_ListBox, m4_ListBox, m5_ListBox
global dic_thumbnail, image
bgLabel = Label(bo_Frame, width=600, height=600, bg='white')
bgLabel.place(x=0, y=0)
list_boxOffice = getXML(yesterday, 0, 0)
init_dateInputLabel()
init_dateSearchButton()
init_SortingButton()
fontemp = font.Font(bo_Frame, size=12, weight='bold')
# BoxOffice Tab Setting Start.
m1_ListBox = Listbox(bo_Frame, font=fontemp, width=37, height=11, borderwidth=2, relief='ridge')
m1_ListBox.place(x=80, y=75)
m2_ListBox = Listbox(bo_Frame, font=fontemp, width=11, height=11, borderwidth=2, relief='ridge')
m2_ListBox.place(x=0, y=400)
m3_ListBox = Listbox(bo_Frame, font=fontemp, width=14, height=11, borderwidth=2, relief='ridge')
m3_ListBox.place(x=105, y=400)
m4_ListBox = Listbox(bo_Frame, font=fontemp, width=12, height=11, borderwidth=2, relief='ridge')
m4_ListBox.place(x=238, y=400)
m5_ListBox = Listbox(bo_Frame, font=fontemp, width=16, height=11, borderwidth=2, relief='ridge')
m5_ListBox.place(x=353, y=400)
dateText = Label(bo_Frame, font=fontemp, bg="grey", fg="black", text="BOX OFFICE ??")
dateText.place(x=180, y=15)
m1_ListBox.bind('<<ListboxSelect>>', listBox_Event)
# BoxOffice Tab Setting End.
def init_dateInputLabel():
global InputLabel
fontemp = font.Font(bo_Frame, size=12, weight='bold')
dateLabel = Label(bo_Frame, font=fontemp, text="?? ??\n(YYYYMMDD)", bg='grey')
dateLabel.place(x=405, y = 13)
InputLabel = Entry(bo_Frame, font=fontemp, width=14, borderwidth=3, relief='ridge')
InputLabel.place(x=520, y=20)
def init_dateSearchButton():
fontemp = font.Font(bo_Frame, size=12, weight='bold')
sButton = Button(bo_Frame, font=fontemp, text = "??", command=lambda: searchButtonAction(0))
sButton.place(x=670, y=17)
def init_searchInputLabel():
global Input_search
fontemp = font.Font(sc_Frame, size=12, weight='bold')
searchLabel = Label(sc_Frame, font=fontemp, text="?? ?? ??", bg = 'grey')
searchLabel.place(x=65, y=10)
Input_search = Entry(sc_Frame, font=fontemp, width=20, borderwidth=3, relief='ridge')
Input_search.place(x=20, y=40)
fontemp = font.Font(sc_Frame, size=12, weight='bold')
sButton = Button(sc_Frame, font=fontemp, text="??", command=lambda : get_search())
sButton.place(x=220, y=37)
def get_search():
global list_movieData, s1_ListBox
q = Input_search.get()
fontemp = font.Font(sc_Frame, size=12, weight='bold')
list_movieData = getXML(q, 1, 0)
s1_ListBox.delete(0,END)
rank = 0;
for i in list_movieData:
rank += 1
s1_ListBox.insert(rank - 1, "- {0}\n".format(i['movieNm']))
def get_movieinfo(q):
global list_movieData, dic_detailData, s2_ListBox
fontemp = font.Font(sc_Frame, size=12, weight='bold')
dic_detailData = getXML(q, 2, 0)
s2_ListBox.delete(0, END)
s2_ListBox.insert(END, "??: {0}\n".format(dic_detailData['movieNm']))
s2_ListBox.insert(END, "?? ??: {0}\n".format(dic_detailData['movieNmEn']))
s2_ListBox.insert(END, "????: {0}?\n".format(dic_detailData['showTm']))
s2_ListBox.insert(END, "???: {0}\n".format(dic_detailData['openDt']))
s2_ListBox.insert(END, "????: {0}\n".format(dic_detailData['nationNm']))
s2_ListBox.insert(END, "??: {0}\n".format(dic_detailData['genreNm']))
s2_ListBox.insert(END, "???: {0}\n".format(dic_detailData['dirNm']))
s2_ListBox.insert(END, "????: {0}\n".format(dic_detailData['watchGradeNm']))
def label_size(self, label):
"""Calculate label size"""
font_family, font_size = self.font
font = Font(family=font_family, size=font_size)
width = 0
lines = 0
for line in label.split('\n'):
width = max(width, font.measure(line))
lines += 1
xscale = turtle.getscreen().xscale
yscale = turtle.getscreen().yscale
return width / xscale, font.metrics('linespace') * lines / yscale
def label_pos(self, pos, label=None, horizontal=False):
"""Calculate label start position (top-right if vertical, top-center if horizontal)"""
xscale = turtle.getscreen().xscale
yscale = turtle.getscreen().yscale
font_family, font_size = self.font
font = Font(family=font_family, size=font_size)
line_height = font.metrics('linespace') / yscale
height = (label.count('\n') + 1) * line_height
return -8 / xscale if horizontal else pos, \
pos - 0.5 * height if horizontal else -height - 6 / yscale
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)
def change_size(self,event):
tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0)
size = tk.customFont["size"]
tk.customFont.configure(size =self.list_size.get(self.list_size.curselection()))
self.st.config(font = tk.customFont)
self.size_count = 1
pass
def change_font(self,event):
tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0)
family = tk.customFont["family"]
tk.customFont.configure(family =self.list_font.get(self.list_font.curselection()))
self.st.config(font = tk.customFont)
self.font_count = 1
pass
def change_shape(self,event):
tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0)
slant = tk.customFont["slant"]
tk.customFont.configure(slant =self.list_shape.get(self.list_shape.curselection()))
self.st.config(font = tk.customFont)
self.shape_count =1
pass
def change_weight(self,event):
tk.customFont = font.Font(family = "Helvetica",size = 12,weight = "normal",slant = "roman",underline =0)
weight = tk.customFont["weight"]
tk.customFont.configure(weight =self.list_weight.get(self.list_weight.curselection()))
self.st.config(font = tk.customFont)
self.shape_count =1
def __init__(self, drs, size_canvas=True, canvas=None):
"""
:param drs: ``DrtExpression``, The DRS to be drawn
:param size_canvas: bool, True if the canvas size should be the exact size of the DRS
:param canvas: ``Canvas`` The canvas on which to draw the DRS. If none is given, create a new canvas.
"""
master = None
if not canvas:
master = Tk()
master.title("DRT")
font = Font(family='helvetica', size=12)
if size_canvas:
canvas = Canvas(master, width=0, height=0)
canvas.font = font
self.canvas = canvas
(right, bottom) = self._visit(drs, self.OUTERSPACE, self.TOPSPACE)
width = max(right+self.OUTERSPACE, 100)
height = bottom+self.OUTERSPACE
canvas = Canvas(master, width=width, height=height)#, bg='white')
else:
canvas = Canvas(master, width=300, height=300)
canvas.pack()
canvas.font = font
self.canvas = canvas
self.drs = drs
self.master = master
def __init__(self, canvas, drs, **attribs):
self._drs = drs
self._canvas = canvas
canvas.font = Font(font=canvas.itemcget(canvas.create_text(0, 0, text=''), 'font'))
canvas._BUFFER = 3
self.bbox = (0, 0, 0, 0)