treeviewcontrol in tkinter.ttk

Wolfgang Meiners WolfgangMeiners01 at web.de
Thu Jun 30 13:08:19 EDT 2011


Hi all,
when i type the following code under python3, version 3.2 using osx 10.6.8:

##############################################################
#! /usr/bin/env python3
# -*- coding: utf-8 -*-

from tkinter import *
from tkinter.ttk import *
from tkinter.font import Font

root = Tk()
tv = Treeview(root, columns=['ad1', 'ad2'])
tv.pack()
tv.heading('#0', text='tree label', anchor=E)
tv.column('#0', anchor=E)
tv.heading('ad1', text='additional info 1', anchor=E)
tv.column('ad1', anchor=E)
tv.heading('ad2', text='additional info 2', anchor=E)
tv.column('ad2', anchor=E)

nd = tv.insert('', 'end', text='left aligned', values=['right aligned',
'right aligned'])
tv.column('#0', width=Font().measure('left aligned'))

for l in ['#0', '#1', '#2']:
    print('column %s \nheading options: %s \ncolumn options %s' %
	 (l, tv.heading(l, option=None), tv.column(l, option=None)))

root.mainloop()
##############################################################

i get the following output:

column #0
heading options: {'tate': '', 'text': 'tree label', 'image': '',
'command': '', 'anchor': 'e'}
column options {'minwidth': 20, 'width': 200, 'id': '', 'anchor': 'e',
'stretch': 1}
column #1
heading options: {'tate': '', 'text': 'additional info 1', 'image': '',
'command': '', 'anchor': 'e'}
column options {'minwidth': 20, 'width': 200, 'id': 'ad1', 'anchor':
'e', 'stretch': 1}
column #2
heading options: {'tate': '', 'text': 'additional info 2', 'image': '',
'command': '', 'anchor': 'e'}
column options {'minwidth': 20, 'width': 200, 'id': 'ad2', 'anchor':
'e', 'stretch': 1}

showing that all elements should be right aligned (anchor:'e').
Nevertheless, all headings are centered, the tree label is left aligned
while the rest is right aligned. This is not what i would expect.

Additional, the column width of the tree label is to small, one
charakter is missing. Can someone explain to me, how to do this the
right way?

Thank you for any hints
Wolfgang



More information about the Python-list mailing list