Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/155.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何制作一个;滚动条“;要标签列表吗?python tkinter_Python_Tkinter - Fatal编程技术网

如何制作一个;滚动条“;要标签列表吗?python tkinter

如何制作一个;滚动条“;要标签列表吗?python tkinter,python,tkinter,Python,Tkinter,这是我的代码: from tkinter import * from PIL import Image, ImageTk im = Image.open(r"1asd.jpg") root = Tk() tkimage = ImageTk.PhotoImage(im) lst = [] for i in range(1, 100): A = Label(root, image=tkimage, text="File number "+str(i), compound=RIGHT)

这是我的代码:

from tkinter import *
from PIL import Image, ImageTk


im = Image.open(r"1asd.jpg")

root = Tk()
tkimage = ImageTk.PhotoImage(im)
lst = []
for i in range(1, 100):
    A = Label(root, image=tkimage, text="File number "+str(i), compound=RIGHT)
    A.config(font=("Courier", 44))
    lst.append(A)

for i in lst:
    i.pack()
root.mainloop()

问题是,我看不到所有的图像,因为它们有太多的内容。如何制作滚动条?我尝试使用“Listbox”对象,但它不允许我在文本旁边放置图像。

尝试这样做

从tkinter导入*
从PIL导入图像,ImageTk
root=Tk()
ws=root.winfo_屏幕宽度()
hs=root.winfo_屏幕高度()
w=1000
h=1000
x=(w/2)-(w/2)
y=(hs/2)-(h/2)
几何体(“%dx%d+%d+%d%”(w,h,x,y))
root.update()
canvas=canvas(root,bg=“Black”,width=root.winfo\u width(),height=root.winfo\u height())
canvas.pack()
im=Image.open(“home.png”)
tkimage=ImageTk.PhotoImage(im)
lst=[]
y=0
对于范围(1100)内的i:
label=label(画布,image=tkimage,text=“File number”+str(i),font=(“Courier”,44),component=RIGHT)
canvas.create_窗口(0,y,窗口=标签,锚点=NW)
y+=60
滚动条=滚动条(画布,方向=垂直,命令=画布.yview)
滚动条放置(relx=1,rely=0,relheight=1,anchor=NE)
canvas.config(yscrollcommand=scrollbar.set,scrollregion=(0,0,0,y))
root.mainloop()

我使用
画布
放置所有标签并滚动它们

您可以在
画布上放置图像
并滚动画布。或者你必须找到如何使用画布上的Fame来创建滚动框架,然后你可以把你的标签放在这里