tkFontBox
This simple python program can be used to make FontChooser dialog in Tkinter Applications.
how to use?
- Copy the tkFontBox.py file into your current directory .
- In your python program, just import it like this.
from tkFontBox import FontChooser - In your python program of tkinter Application, wherever you want, create a method like this:
def getFont():
global fc
try:
fc.deiconify()
except Exception as e: #In the first open fontChooser window object have to be created.
print(e)
fc = FontChooser(root)#then, will have to open fontChooser again.
def printFont():
fn = fc.fontCombo.get()
fs = fc.fontSizeCombo.get()
txtbox.config(font=(fn,fs))
fc.fontCombo.set(fn)
fc.fontSizeCombo.set(fs)
##
fc.withdraw()
## font = fc.getFont()
## txtbox.config(font=font)
fc.openFontDialog.config(command=printFont)
Here, getFont() method can be called by any of your TButtons,menus etc. to get the font family name and font size and use them. under printFont() method "fn" is the variable to get font name and "fs" for font size and "txtbox" (in line 20) is the tkinter textBox in which you may want to change the font name and size you selected.
I'm providing 2 files in this repo, 1. font_chooser_main.py 2. tkFontBox.py first file is the example program which is calling tkFontBox to use FontChooser window. Second is the file which is to be used to make FontChooser dialog box in your python programs using tkinter.
Affected main Window Text of textbox
if you liked this repo,and it really helped you, and want to support me to make more repos. like this,
Subscribe our Youtube Channel : CID An Education Hub
~Thanks and Regards,
Pawan Kumar