Python Forum
[Tkinter] Treeview expand button size
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Treeview expand button size
#1
Dear Friends,

I am new to Python, I have developed an kiosk application whith python in Ubuntu, which I am using treeview to select the folders and files. The challenge I am facing is the expand button of the treeview is small, can we make it bigger since we are using the application in a KIOSK with touch screen, it is too harder to expand.

Any help would be appreciated.
Reply
#2
Download John Shipman's tkinter manual here: http://reu.cct.lsu.edu/documents/Python_...kinter.pdf (a new home hopefully)
tkinter has not changed much (if at all) since this manual was written, so it's still a very viable reference.

Go to page 137 (ttk.Treeview) to get attribute details.

The size of your Treeview is limited by the size of it's container (widget).

When I write a tkinter application, I usually divide the root window into frames, one for each separate part of the overall application, one of those dedicated to a Treeview, Listview, or similar widget (if needed).
If you do this, then you can expand your Treeview to fill the entire frame, set stretch = True so it will expand when the main window expands.

I have an application (though quite old, Sept 2016) where I do this here.
Reply
#3
Thank you very much for the response, In my application I am using multiple Tabs(Notebooks). so I have assigned each Frame for each NoteBook. So would I be able to create a another Frame inside that Frame.?

Is there any other way we can adjust the expand button size?

MainNotebook = ttk.Notebook(Mainwindow, style='TNotebook')
MainNotebook.pack(fill='both',expand=1)
#Defining main Page in Notebook
MainPage= ttk.Frame(MainNotebook, style='TNotebook.Tab')
MainNotebook.add(MainPage, text="Start")
Reply
#4
you can create frame within frame, but it can get tricky.
Tkinter's geometry is, to put it mildly, a pain in the dupa!
If you are willing to sacrifice some time for a beautiful solution, I would recommend switching to kivy, wxpython or Qt5
all of which have a much better geography engine.
wxpython's aui manager for example allows for docking right out of the box.
It's demo program is the cat's meow, example, source and demo all on the same page.
If you'd like to play with a sample, see: https://python-forum.io/Thread-Perfectly...t=wxpython
Reply
#5
As you advised I will try with other solutions as well.

I am planning to have a background image in the window, so if we are using frames, when we run the window in full screen mode , the bg image will be streched and may be blurred, right?
Reply
#6
you need to keep the same aspect ratio on the image

see: https://stackoverflow.com/questions/1652...pect-ratio
Reply
#7
I have tried by referring the example https://stackoverflow.com/questions/1652...pect-ratio
but still the expandbutton has no change in size.

This is my code
import tkinter as tk
from ttkwidgets import CheckboxTreeview
#from Tkconstants import *
r=tk.Tk()

def set_aspect(content_frame, pad_frame, aspect_ratio):
    # a function which places a frame within a containing frame, and
    # then forces the inner frame to keep a specific aspect ratio

    def enforce_aspect_ratio(event):
        # when the pad window resizes, fit the content into it,
        # either by fixing the width or the height and then
        # adjusting the height or width based on the aspect ratio.

        # start by using the width as the controlling dimension
        desired_width = event.width
        desired_height = int(event.width / aspect_ratio)

        # if the window is too tall to fit, use the height as
        # the controlling dimension
        if desired_height > event.height:
            desired_height = event.height
            desired_width = int(event.height * aspect_ratio)

        # place the window, giving it an explicit size
        content_frame.place(in_=pad_frame, x=0, y=0, 
            width=desired_width, height=desired_height)

    pad_frame.bind("<Configure>", enforce_aspect_ratio)

pad_frame = tk.Frame(borderwidth=0, background="bisque", width=200, height=200)
pad_frame.grid(row=0, column=0, sticky="nsew", padx=10, pady=20)
content_frame=tk.Frame(r,borderwidth=5,relief="groove", background="blue")
tk.Label(content_frame,text='content').pack()
set_aspect(content_frame, pad_frame, aspect_ratio=2.0/1.0) 
tree = CheckboxTreeview(content_frame, selectmode = "extended", show="tree", padding=25)
tree.pack(fill='both')
r.rowconfigure(0, weight=1)
r.columnconfigure(0, weight=1)

tree.insert("", "end", "1", text="1")
tree.insert("1", "end", "11", text="11")
tree.insert("1", "end", "12",  text="12")
tree.insert("11", "end", "111", text="111")
tree.insert("", "end", "2", text="2")

r.mainloop()
Reply
#8
Now, this is an experiment. Set all columns of the treeview's stretch attribute to true
this may set the horizontal stretch, but won't help with vertical stretch. (one of the reasons I say tkinter's geometry su...
(Shipman page 141)
Don't know if it will work or not, but worth a try.

see this perhaps? https://stackoverflow.com/a/48065335
Reply
#9
Thank you very much for your help Larz60+,

We have managed to find it out, please add the below lines to the the code and then it will work. The expand button sixe can be adjusted by changing the values of indicatorsize and indicatordiameter
s = ttk.Style()
s.configure(".", indicatorsize = '50', indicatordiameter='50')
s.theme_use('default')
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Search data in treeview without search button TomasSanchexx 3 1,527 Aug-12-2023, 03:17 AM
Last Post: deanhystad
  [Tkinter] [split] Is there a way to embed a treeview as a row inside another treeview? CyKlop 5 3,303 Oct-20-2021, 12:14 AM
Last Post: CyKlop
  [Tkinter] Trying to change font size w/o changing button size python63 3 9,732 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  [PyGUI] Expand last sub-node of treeview widget mart79 1 2,097 Apr-25-2020, 07:57 PM
Last Post: mart79
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 4,949 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Not getting entry values on button click & treeview not updating ? swanysto 4 6,962 May-10-2019, 04:16 PM
Last Post: swanysto
  [Tkinter] Treeview automatically adjust it's size when pack inside frame Prince_Bhatia 1 27,605 Jul-25-2018, 03:24 AM
Last Post: Larz60+
  PyGtk3 why is Locale Folder Size Half of Module Size ? harun2525 1 3,582 Mar-09-2017, 03:46 AM
Last Post: Analyser

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020