Article 5G71H tkinter how to set font for file listing in asksaveasfile()

tkinter how to set font for file listing in asksaveasfile()

by
RockDoctor
from LinuxQuestions.org on (#5G71H)
The code below works properly, but the appearance of the file saving dialog is quite ugly (to me, anyway). Most of the dialog box uses the default font set in the ConvexHull class, but the file listing uses tkinter's default font. Is there a way to make the listbox within the dialog use my preferred font without having to write my own file save dialog?

Code:from tkinter.filedialog import asksaveasfile
...
class ConvexHull:
...
default_font = font.nametofont("TkDefaultFont")
default_font.config(family="Liberation Sans", size=9)
...
def snapshot(self):
""" Grab a screenshot of the full window and save it
Tkinter window grab does not include the window decoration.
I'm using 22 for the height; it's close on my system
"""
dy = 22

# need to locate our window and grab it
w, h = root.winfo_width(), root.winfo_height()
x, y = root.winfo_x(), root.winfo_y()
image = ImageGrab.grab((x, y-dy, x+w, y+h))

filetype = [('Image files: ', '*png *jpg')]
afile = asksaveasfile(
filetypes=filetype,
defaultextension='.png',
title='Save Snapshot',
initialdir='/home/a/Desktop')
image.save(afile.name)
Attached Thumbnailsattachment.php?attachmentid=36032&stc=1& latest?d=yIl2AUoC8zA latest?i=xjpE1NCW__U:Ot6-0f9ylgE:F7zBnMy latest?i=xjpE1NCW__U:Ot6-0f9ylgE:V_sGLiP latest?d=qj6IDK7rITs latest?i=xjpE1NCW__U:Ot6-0f9ylgE:gIN9vFwxjpE1NCW__U
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments