我正在尝试在可滚动的画布上大量填充项目。当我创建一个函数来创建图像标签和按钮时,如果它们位于第0列,一切正常。
但是,如果我将其设置为第1列,它将保持在同一位置。我认为它会与框架有关,所以我尝试更改框架的大小,按钮的大小等更大,并使框架更大,以使canvas_window更大。什么都没有用!
def onFrameConfigure(canvas):
canvas.configure(scrollregion=canvas.bbox("all"))
root = Tk()
canvas = Canvas(root, background="black", width=230)
frame = Frame(canvas, background="white")
vsb = Scrollbar(root, orient="vertical", command=canvas.yview)
canvas.configure(yscrollcommand=vsb.set)
canvas.pack(side="left", fill="both")
vsb.pack(side="left", fill="y")
canvas.create_window((0,0), window=frame, anchor="nw")
frame.bind("<Configure>", lambda event, canvas=canvas: onFrameConfigure(canvas))
def standard_window(frame):
block_name = ["Ixalan", "Amonkhet", "Kaladesh"]
button_command = [test]
first_set_photo = ["ixalan.png", "amonkhet.png", "kaladesh.png"]
second_set_photo = ["ixalan.png", "hour.png", "aether_revolt.png"]
third_set_photo = []
set_1_count = 1
file_count = 0
count = 0
image_row = 0
while count < len(block_name):
photo = PhotoImage(file="{0}".format(first_set_photo[count]))
label = Label(frame, image=photo, fg="white", bg="black")
label.image = photo
label.grid(row=image_row, column=1)
Button(frame, text="{0} BLOCK".format(block_name[file_count]), font=("Helvetica", 8), fg="white", bg="black", command=test).grid(
row = set_1_count, column=0, columnspan=5)
非常感谢你能帮助!!