I've found that althought my fonts are fine everywhere else, they're blocky when I Tkinter. I have an LCD screen, and I'm using Xubuntu with Gnome. They work fine in WxPython.

It seems like Tkinter doesn't allow for sub-pixel rendering or such (at least automatically). Is there some way to turn it on? I have it on already in my operating system. Is there a way to turn it on in Tkinter, or to let it follow the operating system's lead?

They're rather blocky—not just a tad.

Install Tile. Google will give a lot of results about Tile improving Tkinter. Also, try other fonts. I like linux-libertine. This will list the fonts that are available.

from Tkinter import *
from tkFont import families
import Pmw
root = Tk()
Pmw.initialise()

choice = None
comboentries = families(root)

##---  Move from tuple to list and sort
comboentries_list = list(comboentries)
comboentries_list.sort()

label_test = Label(root, text='Test Font',padx=20, pady=10)
label_test.pack(expand=1, fill=BOTH, padx=8, pady=8)

def selectFont(entry):
    label_test.configure(font=(entry,12))

combobox = Pmw.ComboBox(root, label_text='Font:', labelpos='wn',
           listbox_width=24, dropdown=1,
           scrolledlist_items=comboentries_list,
           selectioncommand=selectFont)
combobox.pack(fill=BOTH, expand=1, padx=8, pady=8)
                                                        
combobox.selectitem(comboentries_list[0])
                                                                            
root.mainloop()

Install Tile.

Cool. I've installed it. Now, how do I use it to get this specific effect?

Thanks!

This is a demo found on the web. There may be better ways to do it, but since I don't do much Tk programming, it works fine for me. BTW there is talk of integrating Tile in Python3.0, but so far that is only talk.

from Tkinter import *
 
root = Tk()
root.tk.call('package', 'require', 'tile')
root.tk.call('namespace', 'import', '-force', 'ttk::*')
root.tk.call('::ttk::setTheme', 'alt')
root.geometry("100x50+10+10" )  
v = IntVar()
Radiobutton(root, text="Hello", variable=v, value=1).pack()
Radiobutton(root, text="There", variable=v, value=2).pack()
 
root.mainloop()

Um, I'm not exactly sure why, but my original code now displays things correctly. I installed a few seemingly unrelated things, but I didn't think that would have made the difference (i.e. the newest version of WxPython).

Weird. Well, it doesn't look 100% smooth, but it seems better than before, and looks the same as when I use the code suggested with Tile.

When I tried using Tile, though, as you described, my code for colors and sizes for text controls didn't work anymore. Is there another way to do it?

i.e.
textbox.config(bg="black", fg="yellow")
textbox.config(height=3, width=20)

This article has been dead for over six months. Start a new discussion instead.