I have the following code that generates a template using tkinter.
import os
from tkinter import *
from tkinter import ttk
from PIL import Image,ImageTk
root = Tk()
root.title("Template viewer")
root.geometry("1000x600")
root.resizable(False, False)
# Create A Main frame
main_frame = Frame(root)
main_frame.pack(fill=BOTH,expand=1)
#main_frame.configure(root,background='red') #overlapped with canvas so background color doesnt work
# Create Frame for X Scrollbar
sec = Frame(main_frame)
sec.pack(fill=X,side=BOTTOM)
# Create A Canvas inside the main frame
my_canvas = Canvas(main_frame,background='blue')
my_canvas.pack(side=LEFT,fill=BOTH,expand=1)
# Add A Scrollbars to Canvas
x_scrollbar = ttk.Scrollbar(sec,orient=HORIZONTAL,command=my_canvas.xview)
x_scrollbar.pack(side=BOTTOM,fill=X)
y_scrollbar = ttk.Scrollbar(main_frame,orient=VERTICAL,command=my_canvas.yview)
y_scrollbar.pack(side=RIGHT,fill=Y)
# Configure the canvas
my_canvas.configure(xscrollcommand=x_scrollbar.set)
my_canvas.configure(yscrollcommand=y_scrollbar.set)
my_canvas.bind("<Configure>",lambda e: my_canvas.config(scrollregion= my_canvas.bbox(ALL)))
# Create Another Frame INSIDE the Canvas
second_frame = Frame(my_canvas)
# Add that New Frame a Window In The Canvas
my_canvas.create_window((0,0),window= second_frame, anchor="nw")
lbltwo=Label(my_canvas, text="this is a template", fg='black', bg = 'red', font=("Helvetica", 16))
lbltwo.place(x=0, y=100, anchor = SW)
##add table to the frame
# Create an object of Style widget
style = ttk.Style()
style.theme_use('clam')
# Add a Treeview widget
tree = ttk.Treeview(my_canvas, column=("FName", "LName"), show='headings', height=5)
tree.column("# 1", anchor=CENTER, stretch=NO, width=490)
tree.heading("# 1", text="Column1")
tree.column("# 2", anchor=CENTER, stretch=NO, width=490)
tree.heading("# 2", text="Column2")
# Insert the data in Treeview widget
tree.insert('', 'end', text="1", values=('Entry1', 'file1'))
tree.insert('', 'end', text="1", values=('Entry2', 'file2'))
tree.place(x=0, y=250)
#add image path
img= (Image.open("/path/to/image/file/"))
resized_image= img.resize((500,400)) #Resize the Image using resize method
new_image= ImageTk.PhotoImage(resized_image)
my_canvas.create_image(500,900,anchor=CENTER, image=new_image) #Add image to the Canvas Items
#Add new rectangles to the canvas items
b1 = my_canvas.create_rectangle(0,600,1000,1100, outline="black")
root.mainloop()
It works well without any label or table widgets. But, as I add them they seem to scroll with the canvas and not fixed at their position (top of the page). This makes them overlap the stuff on the bottom of the page. Can anyone suggest how to make these added widgets fixed at specific positions?