I am working on a python tkinter desktop applicaiton. I need a scrollbar on the right side of the frame with a vertical orientation. I am trying to display a ttk scrollbar but it does not seem to display properly. My table disappears and the height of the scrollbar is not correct either. Also, if possible, the scrollbar needs to appear only when the TreeView overflows and when it doesnt overflow, then the scrollbar should not be displayed.
import tkinter
from turtle import color, width
import win32com.client
import sys
import subprocess
import time
from tkinter import*
from tkinter import ttk
from tkinter import messagebox
class TestingGui():
def __init__(self):
print("testing")
def registerUser(self):
userName = "tim"
userAge = "36"
userGender = "male"
userPosition = "softeware engineer"
userInfo = [userName.upper(),userAge,userGender,userPosition]
tree.column(0,anchor='center')
tree.column(1,anchor='center')
tree.column(2,anchor='center')
tree.column(3,anchor='center')
tree.insert('',0,values=userInfo)
if __name__ == '__main__':
window = Tk()
window.title('Dashboard')
window.geometry('925x500+300+200')
window.configure(bg="#fff")
window.resizable(False,False)
################### Frame (Top)[start] #####################################
frameTop = Frame(window,width=860,height=60,bg='white')
frameTop.place(x=40,y=40)
uploadExcelBtn = Button(frameTop,width=19,pady=7,text='Upload Excel',bg='#787c82',fg='white',cursor='hand2',border=0).place(x=715,y=13)
excelFileInputField = Entry(frameTop,width=58,fg='black',border=1,bg='white',font=('Microsoft YaHei UI Light',15,'bold'))
excelFileInputField.place(x=8,y=14)
################### Frame (Top)[end] #######################################
################### Table (Center)[start] #####################################
columns = ('name','age','gender','position')
frameCenter = Frame(window,width=860,height=315,bg='#f0f0f1')
frameCenter.place(x=40,y=110)
treeScroll = ttk.Scrollbar(frameCenter,orient="vertical")
treeScroll.pack(side=RIGHT,fill="y")
tree = ttk.Treeview(frameCenter,height=13,columns=columns,show="headings",selectmode='browse',yscrollcommand=treeScroll.set)
tree.heading('name',text='Name')
tree.heading('age',text='Age')
tree.heading('gender',text='Gender')
tree.heading('position',text='Position')
tree.place(x=30,y=10)
treeScroll.config(command=tree.yview)
################### Table (Center)[end] #######################################
################### Frame (Bottom)[start] #####################################
frameBottom = Frame(window,width=860,height=60,bg='white')
frameBottom.place(x=40,y=430)
addUserBtn = Button(frameBottom,width=19,pady=7,text='Add User',bg='#57a1f8',fg='white',cursor='hand2',border=0,command= lambda : TestingGui().registerUser()).place(x=30,y=15)
################### Frame (Bottom)[end] #######################################
mainloop()