Python Forum

Full Version: Treeview automatically adjust it's size when pack inside frame
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, i have a question, i am creating a tkinter project where i will display data into tkinter window from database. For this i am using tkk treeview but as i run the code my treeview automatically adjusts it's height . It doesn't go according to the frame i am fitting my treeview into.
One more things i have created two frames for top and bottom but when i create button frames get shrinked to the size of button ? Why does it happen?
Please help

Below are codes
from tkinter import ttk

import tkinter as tk

import sqlite3

from tkinter import *

 

def View():

    conn = sqlite3.connect("99_data_increment.db")

    cur = conn.cursor()

    cur.execute("SELECT * FROM crawled")

    rows = cur.fetchall()

    for row in rows:

        tree.insert("", tk.END, values=row)

    conn.close()

 

root = tk.Tk()

root.geometry("1250x650+0+0")

root.title("MAYA")

root.configure(background="gray28")

 

Tops = Frame(root, width=1200, height=100,bd=14, relief="raise")

Tops.pack(side=TOP)

 

frame1 = Frame(root, width=1200, height=450,bd=15,relief="raise")

frame1.pack()

 

tree= ttk.Treeview(frame1, column=("column1", "column2", "column3", "column4", "column5","column6", "column7", "column8", "column9", "column10", "column11", "column12", "column13", "column14", "column15", "column16", "column17", "column18" ), show='headings')

tree.heading("#1", text="ID")

tree.heading("#2", text="STATE")

tree.heading("#3", text="XID")

tree.heading("#4", text="PROJECT NAME")

tree.heading("#5", text="CITY")

tree.heading("#6", text="MAIN CITY")

tree.heading("#7", text="REGISTRATION NUMBER")

tree.heading("#8", text="PROMOTER NAME")

tree.heading("#9", text="RERA URL")

tree.heading("#10", text="PDF NUMBER")

tree.heading("#11", text="CRAWLED DATE")

tree.heading("#12", text="STATUS")

tree.heading("#13", text="NAMES")

tree.heading("#14", text="TRANSACTION DATE")

tree.heading("#15", text="COMMENTS")

tree.heading("#16", text="CALL CONTACT NUMBER")

tree.heading("#17", text="CREATION TYPE")

tree.heading("#18", text="BUILDER WEBSITE")

tree.pack()

 

 

belows = Frame(root, width=1150, height=100, bd=14, relief="raise")

belows.pack(side=BOTTOM)

 

btnrefresh = Button(belows, fg="black", font=("arial", 8, "bold"),width=5,

                   text="REFRESH DATA", command=View).pack(side=LEFT)

 

root.mainloop()
With proper use of grid geometry and sizing weights you can control geometry in tkinter, but it's quite difficult to get it right. This is the main reason why I switched to wxpython phoenix where resizing, docking and undocking, and many other things are so much easier, not to mention the large library of widgets. Qt5 is also a great GUI library, written in C, but has excellent python support (pyQt5), and reciently announced even greater support for python.

I use either a tkinter treeview or list view in this program: https://github.com/Larz60p/CaliforniaPublicSalaries
and figured out pretty much how to properly size the view. But even here, resizing doesn't work properly.
You might be able to garner something from this, it was written quite a while ago, so not so sure of it's value.

This would have been a one night project if I had used wxpython.