Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hitting toggle CheckButton repeatedly causes TreeView to keep expanding #8

Open
sanketss84 opened this issue Jul 22, 2023 · 4 comments
Labels
bug Something isn't working

Comments

@sanketss84
Copy link

sanketss84 commented Jul 22, 2023

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
Copy link
Owner

rdbende commented Jul 23, 2023

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

@rdbende rdbende added the bug Something isn't working label Jul 23, 2023
@sanketss84
Copy link
Author

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
Copy link

leavul commented Aug 1, 2023

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
Copy link

     # 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants