Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # font_viewer_template.py
- from tkinter import *
- from tkinter import font ### note: oddly, if this line is deleted... it will not work as is
- clippy = Tk()
- clippy.withdraw()
- root=Tk()
- root.geometry('1280x640+0+0')
- fonts=list(font.families())
- fonts.sort()
- ffff=Listbox(root)
- ffff.pack(fill=BOTH,expand=YES,side=LEFT)
- scroll=Scrollbar(root)
- scroll.pack(side=LEFT,fill=Y,expand=NO)
- scroll.configure(command=ffff.yview)
- ffff.configure(yscrollcommand=scroll.set)
- test='''ABCDEFGHIJKLMNOPQRSTUVW...
- abcdefghijklmnopqrstuvwxyz XYZ
- 0123456789
- !?'#"$@()[]{~_^}*+,-.:;=<>%&/\`|'''+'\n'
- abc='"My Black Quartz Sphinx, Judge Of Vows!"'
- itSw=['',' italic']
- bbSw=['',' bold']
- family,ffSz='Arial',' 12'
- current_font=[0]
- view='You May Also View Your Choice Of Text Sample Above From The Entry Below...\t'
- view+='**Shift+Z copies to clipboard...\t\t'
- def save2clippy(null):
- sss = '__font = "'+current_font[0].strip()+'"'
- print('*** also copied to the clipboard -- press ctrl+v within a text entry to paste it')
- print(sss)
- clippy.clipboard_clear()
- clippy.clipboard_append(sss)
- def setFont():
- update=(family,ffSz,'%s %s' % (itSw[0],bbSw[0]))
- current_font[0] = ' '.join([str(z) for z in update])
- label.config(font=update)
- def resize(e):
- global ffSz
- ffSz=scale.get()
- setFont()
- def setText(e):
- ttt=text.get(1.0, END)
- if len(ttt) < 2:
- ttt=abc
- label.config(text=test+ttt)
- def familySw(e):
- global family
- family=ffff.get(ffff.curselection()[0])
- margin.config(text=view+family)
- setFont()
- def italicSw():
- global itSw
- itSw=(itSw[1],itSw[0])
- setFont()
- def boldSw():
- global bbSw
- bbSw=(bbSw[1],bbSw[0])
- setFont()
- topFrame = LabelFrame(root,text="",height=560)
- topFrame.pack(fill=X)
- topFrame.pack_propagate(False)
- label=Label(topFrame,text=test+abc,font=family+ffSz,padx=10,justify=LEFT,anchor='nw')
- label.pack(fill=BOTH,expand=YES)
- label.pack_propagate(False)
- margin=Label(root,text=view+family,bg='yellow',width=240,anchor='nw',padx=10)
- margin.pack()
- SLstart,SLend = 6,100
- SL=300
- lf = LabelFrame(root,text="Font Size",width=360,height=58)
- lf.pack(side=LEFT)
- lf.pack_propagate(False)
- scale = Scale(lf,from_=SLstart,to=SLend,orient=HORIZONTAL,length=SL,command=resize)
- scale.set(12)
- scale.pack(fill=X,expand=YES)
- checkBold=Checkbutton(root,text="Bold",anchor='sw',command=boldSw)
- checkBold.pack(side=LEFT,padx=10)
- checkItalic=Checkbutton(root,text="Italic",anchor='sw',command=italicSw)
- checkItalic.pack(side=LEFT,padx=10)
- text=Text(root,font=(family,ffSz),width=480,height=3)
- text.insert(END,abc)
- text.pack(side=LEFT,padx=10,fill=Y)
- text.bind(sequence='<KeyRelease>', func=setText)
- ffff.bind(sequence='<<ListboxSelect>>', func=familySw)
- root.bind('<Shift-KeyPress-Z>', save2clippy)
- for item in fonts:
- ffff.insert(END,item)
- root.mainloop()
Add Comment
Please, Sign In to add comment