please i have a little problem white my code and i hope you can help me guys,
i'm using a scrollbar to scroll over images in my text widget, but the problem is that the tab window is covered by the images when i scroll.
this last picture shows the problem, and i want the tabs to remain showing when i scroll and the images should stay inside the tab. here's the code i used:
import tkinter as tk
from PIL import ImageTk, Image
from os import listdir
from os.path import isfile, join
from tkinter import ttk
def getPaths():
path = "C://Users/poste/Desktop/trainCascade/p"
onlyfiles = [f for f in listdir(path) if isfile(join(path, f))]
return onlyfiles
class Example(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent)
style = ttk.Style()
style.theme_create('pastel', settings={
".": {
"configure": {
"background": 'white', # All except tabs
"font": 'red'
}
},
"TNotebook": {
"configure": {
"background": '#848a98', # Your margin color
"tabmargins": [2, 5, 0, 0], # margins: left, top, right, separator
}
},
"TNotebook.Tab": {
"configure": {
"background": '#d9ffcc', # tab color when not selected
"padding": [10, 2],
"font": "white"
},
"map": {
"background": [("selected", '#ccffff')], # Tab color when selected
"expand": [("selected", [1, 1, 1, 0])] # text margins
}
}
})
style.theme_use('pastel')
tabControl = ttk.Notebook(self)
tab1 = ttk.Frame(tabControl)
tab2 = ttk.Frame(tabControl)
tabControl.add(tab1, text='Tab 1')
tabControl.add(tab2, text='Tab 2')
tabControl.pack(expand=1, fill="both")
text = tk.Text(tab1, wrap="none")
vsb = tk.Scrollbar(tab1, orient="vertical", command=text.yview)
text.configure(yscrollcommand=vsb.set)
vsb.pack(side="right", fill="y")
text.pack(fill="both", expand=True)
img = []
resized = []
final = []
label = []
flag = 0
for i in range(len(getPaths())):
img.append(Image.open("C://Users/poste/Desktop/trainCascade/p/"+getPaths()[i]))
resized.append(img[i].resize((107, 80), Image.ANTIALIAS))
final.append(ImageTk.PhotoImage(resized[i]))
label.append(tk.Label(image=final[i], bg='white'))
label[i].image = final[i]
text.window_create("end", window=label[i])
flag+=1
if flag==5:
text.insert("end", "\n")
flag=0
text.configure(state="disabled")
if __name__ == "__main__":
root = tk.Tk()
root.geometry("575x400")
Example(root).pack(fill="both", expand=True)
root.mainloop()