-
Notifications
You must be signed in to change notification settings - Fork 0
/
fontbox.py
116 lines (103 loc) · 5.99 KB
/
fontbox.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import tkinter
from tkinter import ttk
class Font_wm(tkinter.Toplevel):
def __init__(self, Font=None):
tkinter.Toplevel.__init__(self)
self.mainfont=Font
self.title('Font ...')
# Variable
self.var=tkinter.StringVar()# For Font Face
self.var.set(self.mainfont.actual('family'))
self.var1=tkinter.IntVar() # for Font Size
self.var1.set(self.mainfont.actual('size'))
self.var2=tkinter.StringVar() # For Bold
self.var2.set(self.mainfont.actual('weight'))
self.var3=tkinter.StringVar() # For Italic
self.var3.set(self.mainfont.actual('slant'))
self.var4=tkinter.IntVar()# For Underline
self.var4.set(self.mainfont.actual('underline'))
self.var5=tkinter.IntVar() # For Overstrike
self.var5.set(self.mainfont.actual('overstrike'))
# Font Sample
self.font_1=tkinter.font.Font()
for i in ['family', 'weight', 'slant', 'overstrike', 'underline', 'size']:
self.font_1[i]=self.mainfont.actual(i)
# Function
def checkface(event):
try:
self.var.set(str(self.listbox.get(self.listbox.curselection())))
self.font_1.config(family=self.var.get(), size=self.var1.get(), weight=self.var2.get(), slant=self.var3.get(), underline=self.var4.get(), overstrike=self.var5.get())
except:
pass
def checksize(event):
try:
self.var1.set(int(self.size.get(self.size.curselection())))
self.font_1.config(family=self.var.get(), size=self.var1.get(), weight=self.var2.get(), slant=self.var3.get(), underline=self.var4.get(), overstrike=self.var5.get())
except:
pass
def applied():
self.result=(self.var.get(), self.var1.get(), self.var2.get(), self.var3.get(), self.var4.get(), self.var5.get())
self.mainfont['family']=self.var.get()
self.mainfont['size']=self.var1.get()
self.mainfont['weight']=self.var2.get()
self.mainfont['slant']=self.var3.get()
self.mainfont['underline']=self.var4.get()
self.mainfont['overstrike']=self.var5.get()
def out():
self.result=(self.var.get(), self.var1.get(), self.var2.get(), self.var3.get(), self.var4.get(), self.var5.get())
self.mainfont['family']=self.var.get()
self.mainfont['size']=self.var1.get()
self.mainfont['weight']=self.var2.get()
self.mainfont['slant']=self.var3.get()
self.mainfont['underline']=self.var4.get()
self.mainfont['overstrike']=self.var5.get()
self.destroy()
def end():
self.result=None
self.destroy()
# Main window Frame
self.mainwindow=ttk.Frame(self)
self.mainwindow.pack(padx=10, pady=10)
# Main LabelFrame
self.mainframe=ttk.Frame(self.mainwindow)
self.mainframe.pack(side='top',ipady=30, ipadx=30,expand='no', fill='both')
self.mainframe0=ttk.Frame(self.mainwindow)
self.mainframe0.pack(side='top', expand='yes', fill='x', padx=10, pady=10)
self.mainframe1=ttk.Frame(self.mainwindow)
self.mainframe1.pack(side='top',expand='no', fill='both')
self.mainframe2=ttk.Frame(self.mainwindow)
self.mainframe2.pack(side='top',expand='yes', fill='x', padx=10, pady=10)
# Frame in [ main frame]
self.frame=ttk.LabelFrame(self.mainframe, text='Select Font Face')
self.frame.pack(side='left', padx=10, pady=10, ipadx=20, ipady=20, expand='yes', fill='both')
self.frame1=ttk.LabelFrame(self.mainframe, text='Select Font size')
self.frame1.pack(side='left', padx=10, pady=10, ipadx=20, ipady=20, expand='yes', fill='both')
ttk.Entry(self.frame, textvariable=self.var).pack(side='top', padx=5, pady=5, expand='yes', fill='x')
self.listbox=tkinter.Listbox(self.frame, bg='gray70')
self.listbox.pack(side='top', padx=5, pady=5, expand='yes', fill='both')
for i in tkinter.font.families():
self.listbox.insert(tkinter.END, i)
# Frame in [ 0. mainframe]
self.bold=ttk.Checkbutton(self.mainframe0, text='Bold', onvalue='bold', offvalue='normal', variable=self.var2)
self.bold.pack(side='left',expand='yes', fill='x')
self.italic=ttk.Checkbutton(self.mainframe0, text='Italic', onvalue='italic', offvalue='roman',variable=self.var3)
self.italic.pack(side='left', expand='yes', fill='x')
self.underline=ttk.Checkbutton(self.mainframe0, text='Underline',onvalue=1, offvalue=0, variable=self.var4)
self.underline.pack(side='left', expand='yes', fill='x')
self.overstrike=ttk.Checkbutton(self.mainframe0, text='Overstrike',onvalue=1, offvalue=0, variable=self.var5)
self.overstrike.pack(side='left', expand='yes', fill='x')
# Frame in [ 1. main frame]
ttk.Entry(self.frame1, textvariable=self.var1).pack(side='top', padx=5, pady=5, expand='yes', fill='x')
self.size=tkinter.Listbox(self.frame1, bg='gray70')
self.size.pack(side='top', padx=5, pady=5, expand='yes', fill='both')
for i in range(30):
self.size.insert(tkinter.END, i)
tkinter.Label(self.mainframe1, bg='white',text='''
ABCDEabcde12345
''', font=self.font_1).pack(expand='no', padx=10,pady=10)
# Frame in [ 2. mainframe]
ttk.Button(self.mainframe2, text=' OK ', command=out).pack(side='left', expand='yes', fill='x', padx=5, pady=5)
ttk.Button(self.mainframe2, text=' Cancel ', command=end).pack(side='left', expand='yes', fill='x', padx=5, pady=5)
ttk.Button(self.mainframe2, text=' Apply ', command=applied).pack(side='left', expand='yes', fill='x', padx=5, pady=5)
self.listbox.bind('<<ListboxSelect>>', checkface)
self.size.bind('<<ListboxSelect>>', checksize)