Python Tkinter:Frames 不会互相攻击

Python Tkinter:Frames are not going under each otheer

我正在制作一个简单的 tkinter GUI,其中有滚动框架,但它并不是那么完美 me.At 首先我只使用了一个框架,但是我发现框架有一个限制不。他们可以容纳的小部件,所以我开始使用多个框架。但是我得到这个 problem:the 帧没有按照我 wanted.I 想要帧在前一帧下面的方向进行,但是帧一个在另一个上面,这是相同的屏幕截图:

(第0帧为第一帧)

这是代码(我只保留了重要的部分)

i=0
image_no=0
for video in videos:
    
    u = urllib.request.urlopen(video["thumbnail"]["thumbnails"][0]["url"])
    raw_data = u.read()
    u.close()

    im = Image.open(BytesIO(raw_data))
    image = ImageTk.PhotoImage(im.resize((470,210)))
    a.append(image)

    tk.Label(fr[i], image=a[image_no]).pack()
    image_no+=1
    tk.Label(fr[i], text=("Video:"+str(image_no)+" frame:"+str(i)),wraplength=470,font=("ariel",11,"bold"),bg="white").pack()
    tk.Label(fr[i], text=video["title"]["accessibility"]["accessibilityData"]['label'].replace(video["title"]["runs"][0]["text"],""),wraplength=470,font=("ariel",10),bg="white",fg="grey").pack(anchor="w")
    canvas.configure(yscrollcommand=scroll_y.set)

    canvas.configure(scrollregion=canvas.bbox("all"))
    print(image_no)
    print(video["title"]["runs"][0]["text"])
    if image_no%10==0:
        time.sleep(3)
    if image_no%110==0:
        i+=1
    if image_no%440==0:
        break

有什么办法让它往下走吗?

编辑:

这里是帧数限制的截图

黑色区域是canvas

这里有一个link问题tkinter maximum canvas size?

我已经修改了代码,因为可能是图像数量造成的,或者 canvas 可能有一些最大高度。

这将用图像填充整个 canvas 高度,每个图像之间有 10 磅 space。

我已将其更新为 python 3.x 并将高度增加到 100000!

工作没有问题。

选择您自己的图片(gif 或 png)

import tkinter as tk
from tkinter import filedialog as fido

root = tk.Tk()
root.rowconfigure(0, weight = 1)
root.columnconfigure(0, weight = 1)

picture = fido.askopenfilename(title = "Pick a pic")

iconimage = tk.PhotoImage(file = picture)
wide, high = iconimage.width(), iconimage.height()

frame = tk.LabelFrame(root, labelanchor = "s", text = "0|0")
frame.grid(row = 0, column = 0, sticky = "nsew")
frame.rowconfigure(0, weight = 1)
frame.columnconfigure(0, weight = 1)

cv = tk.Canvas(
    frame, width = 1200, height = 700,
    scrollregion = "0 0 2000 100000")
cv.grid(row = 0, column = 0, sticky = "nsew")

vscrollbar = tk.Scrollbar(
    frame, orient = "vertical", command = cv.yview)
vscrollbar.grid(row = 0, column = 1, sticky = "ns")
cv.config(yscrollcommand = vscrollbar.set)

def rowcol(ev):
    frame["text"] = f"{cv.canvasx(ev.x)} | {cv.canvasy(ev.y)}"

cv.bind("<Motion>", rowcol)
root.update()

testimage = []
for pos in range( 0, 100000 - high - 10, high + 10):
     testimage.append(cv.create_image(100, pos, anchor = "nw", image = iconimage))

print(f"Number of images = {len(testimage)}, width = {wide}, height = {high}")

root.mainloop()

所以这似乎不是Canvas高度或显示图像数量的限制。