Python Forum
[Tkinter] Horizontal extension of widgets + frame size adapted to content
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Horizontal extension of widgets + frame size adapted to content
#2
I found solutions to those challenges.

For 1st one:
#Issue was with line 23
self.canvas_summary.create_window((0, 0), window=self.frame_containermain, anchor=tk.NW)


## replaced by:


self.frame_containermain.pack(fill=tk.BOTH, expand=True)
For 2nd one, what I did was to introduce a vertical scrollbar related to my treeview
        self.treeview_summary = ttk.Treeview(self.frame_summary, columns=("Initiative ID", "Owner", "Initiative name", "Total Score", "Decision"))
        self.treeview_summary.heading("#0", text="", anchor=tk.W)  
        self.treeview_summary.heading("Initiative ID", text="Initiative ID", anchor=tk.W)
        self.treeview_summary.heading("Owner", text="Owner", anchor=tk.W)
        self.treeview_summary.heading("Initiative name", text="Initiative name", anchor=tk.W)
        self.treeview_summary.heading("Total Score", text="Total Score", anchor=tk.W)
        self.treeview_summary.heading("Decision", text="Decision", anchor=tk.W)
        self.treeview_summary.pack(fill=tk.BOTH, expand=True)
 
 
        #Load data's from SQLite
        self.load_data()
 
        # Link data loading function to event window resize
        self.master.bind("<Configure>", self.on_window_resize)
 
        # Config canvas canvas_summary to adapt size to content
        self.master.bind("<Configure>", self.on_configure2)


## replaced by:


self.treeview_summary = ttk.Treeview(self.frame_summary, columns=("Initiative ID", "Owner", "Initiative name", "Total Score", "Decision"))
        # +++++++
        #self.treeview_summary.pack()
        # _______
        self.treeview_summary.heading("#0", text="", anchor=tk.W)
        self.treeview_summary.heading("Initiative ID", text="Initiative ID", anchor=tk.W)
        self.treeview_summary.heading("Owner", text="Owner", anchor=tk.W)
        self.treeview_summary.heading("Initiative name", text="Initiative name", anchor=tk.W)
        self.treeview_summary.heading("Total Score", text="Total Score", anchor=tk.W)
        self.treeview_summary.heading("Decision", text="Decision", anchor=tk.W)
        self.treeview_summary.pack(fill="both", expand=True)  # Utilisation de pack pour placer le tableau

        # Configurer le frame_summary pour s'étendre automatiquement en hauteur
        self.frame_summary.pack_propagate(False)

        # Charger les données initiales
        self.load_data()

        # +++++++
        # Créer une barre de défilement vertical
        scrollbar_treeviewsummary = tk.Scrollbar(self.treeview_summary, orient=tk.VERTICAL, command=self.treeview_summary.yview)
        scrollbar_treeviewsummary.pack(side=tk.RIGHT, fill=tk.Y)
        # Configurer le treeview pour utiliser la barre de défilement
        self.treeview_summary.config(yscrollcommand=scrollbar_treeviewsummary.set)
Reply


Messages In This Thread
RE: Horizontal extension of widgets + frame size adapted to content - by Fab117 - Feb-21-2024, 03:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] using different frame for some widgets rwahdan 1 2,432 Jul-13-2021, 08:32 AM
Last Post: Yoriz
  [Tkinter] Trying to change font size w/o changing button size python63 3 10,005 Aug-05-2020, 01:04 AM
Last Post: Larz60+
  [PyQt] Help: check content of combobox in horizontal header of QTableWidget mart79 1 3,444 Jul-26-2020, 06:18 PM
Last Post: deanhystad
  [Tkinter] Scrollbar, Frame and size of Frame Maksim 2 9,172 Sep-30-2019, 07:30 AM
Last Post: Maksim
  Require scroll bars horizontal and vertical throughout the window tejgandhi 2 2,760 Jun-28-2019, 03:13 AM
Last Post: tejgandhi
  [Tkinter] create and insert a new frame on top of another frame atlass218 4 11,342 Apr-18-2019, 05:36 PM
Last Post: atlass218
  [Tkinter] Treeview automatically adjust it's size when pack inside frame Prince_Bhatia 1 28,116 Jul-25-2018, 03:24 AM
Last Post: Larz60+
  [Tkinter] Frame size only works if frame is empty(Solved) Tuck12173 7 6,598 Jan-29-2018, 10:44 PM
Last Post: Larz60+
  PyGtk3 why is Locale Folder Size Half of Module Size ? harun2525 1 3,678 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