Tola
Tola

Reputation: 264

Python 3.x - Tkinter treeview change from one style to another

Below I define two different treeveiw styles. Initially I assign one of them to the a treeview. Is it possible, later on, to shift to the other style?

from tkinter import *
from tkinter import ttk

if __name__ == '__main__':
    root = Tk()
    style = ttk.Style()

    #Defining style 1
    style.configure('myStyle1.Treeview', rowheight=75)
    #Defining style 2
    style.configure('myStyle2.Treeview', rowheight=25)

    tree = ttk.Treeview(root, style='myStyle1.Treeview')
    tree.pack()

    for i in range(5):
        tree.insert(parent='',
               index=END,
               text='item {}'.format(i))


    root.mainloop()   

Upvotes: 0

Views: 780

Answers (1)

Bryan Oakley
Bryan Oakley

Reputation: 386010

Like with any other widget, you can change almost any configuration option at any time. The style is no different in this regard.

tree.configure(style='myStyle2.Treeview')

Upvotes: 2

Related Questions