here2share

# font_viewer_template.py

Apr 20th, 2020 (edited)
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.83 KB | None | 0 0
  1. # font_viewer_template.py
  2.  
  3. from tkinter import *
  4. from tkinter import font ### note: oddly, if this line is deleted... it will not work as is
  5.  
  6. clippy = Tk()
  7. clippy.withdraw()
  8.  
  9. root=Tk()
  10. root.geometry('1280x640+0+0')
  11.  
  12. fonts=list(font.families())
  13. fonts.sort()
  14.  
  15. ffff=Listbox(root)
  16. ffff.pack(fill=BOTH,expand=YES,side=LEFT)
  17.  
  18. scroll=Scrollbar(root)
  19. scroll.pack(side=LEFT,fill=Y,expand=NO)
  20.  
  21. scroll.configure(command=ffff.yview)
  22. ffff.configure(yscrollcommand=scroll.set)
  23.  
  24. test='''ABCDEFGHIJKLMNOPQRSTUVW...
  25. abcdefghijklmnopqrstuvwxyz XYZ
  26. 0123456789
  27. !?'#"$@()[]{~_^}*+,-.:;=<>%&/\`|'''+'\n'
  28.  
  29. abc='"My Black Quartz Sphinx, Judge Of Vows!"'
  30.  
  31. itSw=['',' italic']
  32. bbSw=['',' bold']
  33. family,ffSz='Arial',' 12'
  34. current_font=[0]
  35.  
  36. view='You May Also View Your Choice Of Text Sample Above From The Entry Below...\t'
  37. view+='**Shift+Z copies to clipboard...\t\t'
  38.  
  39. def save2clippy(null):
  40.     sss = '__font = "'+current_font[0].strip()+'"'
  41.     print('*** also copied to the clipboard -- press ctrl+v within a text entry to paste it')
  42.     print(sss)
  43.     clippy.clipboard_clear()
  44.     clippy.clipboard_append(sss)
  45.  
  46. def setFont():
  47.     update=(family,ffSz,'%s %s' % (itSw[0],bbSw[0]))
  48.     current_font[0] = ' '.join([str(z) for z in update])
  49.     label.config(font=update)
  50.  
  51. def resize(e):
  52.     global ffSz
  53.     ffSz=scale.get()
  54.     setFont()
  55.  
  56. def setText(e):
  57.     ttt=text.get(1.0, END)
  58.     if len(ttt) < 2:
  59.             ttt=abc
  60.     label.config(text=test+ttt)
  61.  
  62. def familySw(e):
  63.     global family
  64.     family=ffff.get(ffff.curselection()[0])
  65.     margin.config(text=view+family)
  66.     setFont()
  67.  
  68. def italicSw():
  69.     global itSw
  70.     itSw=(itSw[1],itSw[0])
  71.     setFont()
  72.  
  73. def boldSw():
  74.     global bbSw
  75.     bbSw=(bbSw[1],bbSw[0])
  76.     setFont()
  77.  
  78. topFrame = LabelFrame(root,text="",height=560)
  79. topFrame.pack(fill=X)
  80. topFrame.pack_propagate(False)
  81.  
  82. label=Label(topFrame,text=test+abc,font=family+ffSz,padx=10,justify=LEFT,anchor='nw')
  83. label.pack(fill=BOTH,expand=YES)
  84. label.pack_propagate(False)
  85.  
  86. margin=Label(root,text=view+family,bg='yellow',width=240,anchor='nw',padx=10)
  87. margin.pack()
  88.  
  89. SLstart,SLend = 6,100
  90. SL=300
  91.  
  92. lf = LabelFrame(root,text="Font Size",width=360,height=58)
  93. lf.pack(side=LEFT)
  94. lf.pack_propagate(False)
  95.  
  96. scale = Scale(lf,from_=SLstart,to=SLend,orient=HORIZONTAL,length=SL,command=resize)
  97. scale.set(12)
  98. scale.pack(fill=X,expand=YES)
  99.  
  100. checkBold=Checkbutton(root,text="Bold",anchor='sw',command=boldSw)
  101. checkBold.pack(side=LEFT,padx=10)
  102.  
  103. checkItalic=Checkbutton(root,text="Italic",anchor='sw',command=italicSw)
  104. checkItalic.pack(side=LEFT,padx=10)
  105.  
  106. text=Text(root,font=(family,ffSz),width=480,height=3)
  107. text.insert(END,abc)
  108. text.pack(side=LEFT,padx=10,fill=Y)
  109. text.bind(sequence='<KeyRelease>', func=setText)
  110. ffff.bind(sequence='<<ListboxSelect>>', func=familySw)
  111. root.bind('<Shift-KeyPress-Z>', save2clippy)
  112.  
  113. for item in fonts:
  114.     ffff.insert(END,item)
  115.  
  116. root.mainloop()
Add Comment
Please, Sign In to add comment