0

I am trying to implement treeview in tkinter with scrollbar. I have got success in placing scrollbar but unable to place it in proper place. Following is full code:

from tkinter import* from tkinter import ttk import sqlite3 class Product: db_name = 'Gateway_Log.db' def __init__(self,wind): self.wind=wind self.wind.title('Device details') self.tree = ttk.Treeview (height=25, columns=2) self.tree.heading('#0',text = 'Name', anchor=W) self.tree.heading(2, text='Price', anchor=W) vsb = ttk.Scrollbar(wind, orient="vertical") vsb.configure(command=self.tree.yview) self.tree.configure(yscrollcommand=vsb.set) self.tree.pack() vsb.pack() self.viewing_records() def run_query(self, query, parameters =()): with sqlite3.connect (self.db_name) as conn: cursor = conn.cursor() query_result=cursor.execute(query, parameters) conn.commit() return query_result def viewing_records(self): records = self.tree.get_children() for element in records: self.tree.delete(element) query= 'SELECT * FROM Device_Status' db_rows=self.run_query(query) for row in db_rows: self.tree.insert('',0, text = row[0], values = row[1]) if __name__ == '__main__': wind=Tk() application = Product(wind) wind.mainloop() 

Following output I am getting:

enter image description here

I want scrollbar after price field not at bottom side.

1 Answer 1

2

You need to indicate the side where you want to pack your widget and also which direction it should fill.

self.tree.pack(side="left") vsb.pack(side="right",fill="y") 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.