rdbende / Forest-ttk-theme

A beautiful modern theme for ttk, inspired by MS Excel's look 🌲🌳
MIT License
312 stars 84 forks source link

hitting toggle CheckButton repeatedly causes TreeView to keep expanding #8

Open sanketss84 opened 11 months ago

sanketss84 commented 11 months ago

This is my code. If I keep hitting that toggle button the treeview just keeps expanding and finally goes out of screen.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()
style = ttk.Style(root) 
root.tk.call('source','./forest-light.tcl')
root.tk.call('source','./forest-dark.tcl')
style.theme_use('forest-dark')

def toggle_mode():
    if mode_switch.instate(['selected']):
        style.theme_use('forest-light')
    else:
        style.theme_use('forest-dark')

frame = ttk.Frame(root)
frame.pack()

widgets_frame = ttk.LabelFrame(frame, text='Label Frame')
widgets_frame.grid(row=0,column=0,padx=20,pady=10)

mode_switch = ttk.Checkbutton(widgets_frame,text='Mode',style='Switch', command=toggle_mode)
mode_switch.grid(row=0,column=0,padx=5,pady=10,sticky='nsew')

tree_frame = ttk.Frame(frame)
tree_frame.grid(row=0,column=1,pady=10)

# scrollbar needs to be added and attached to treeview
treescroll = ttk.Scrollbar(tree_frame)
treescroll.pack(side='right',fill='y') # fill entire vertical axis 

# treeview
excel_columns = ['name','age','subscription','employment']

treeview = ttk.Treeview(tree_frame,
                        show='headings',
                        columns=excel_columns, 
                        height=11, 
                        yscrollcommand=treescroll.set)

treeview.column('name',width=100)
treeview.column('age',width=40)
treeview.column('subscription',width=100)
treeview.column('employment',width=100)

treeview.pack()
treescroll.config(command=treeview.yview) 

root.mainloop()

I was following a tutorial based of here https://github.com/codefirstio/tkinter-excel-app/blob/main/main.py https://www.youtube.com/watch?v=8m4uDS_nyCk&ab_channel=CodeFirstwithHala

rdbende commented 11 months ago

Refs.: https://core.tcl-lang.org/tk/tktview?name=bc602049ab https://github.com/rdbende/Azure-ttk-theme/issues/40 https://github.com/rdbende/Sun-Valley-ttk-theme/issues/11

sanketss84 commented 11 months ago

Thanks for sharing the specifics. I have right now decided to remove the toggle button altogether and instead will use the config file to set the theme for my use case which seems to be a suitable solution for my need.

leavul commented 11 months ago

Thanks for sharing the specifics. I have right now decided to remove the toggle button altogether and instead will use the config file to set the theme for my use case which seems to be a suitable solution for my need.

I'm not good at English, I looked at the links but I don't understand, guys, is there a solution for this problem? And how?

mijung2024 commented 10 months ago
     # Treeview
    ttk::style element create Treeview.field image $I(card) \
        -border 5\
        -width 0\
        -height 0\

For each light and dark tcl file, add the last two lines of code ( -width 0\ -height 0) at ttk::style element create Treeview.field image $I(card). Hitting the toggle check button will no longer cause TreeView to keep expanding!