我用 Python 写了一个程序。但我想知道是否有更短的方法可以做到这一点。特别是关于“Canvas”、“Frame”、“LabelFrame”和“Label”,有没有其他方法可以自动制作“scrollregion”(而不是我写的,如果可能的话,在 Tkinter 中使用自然方式)
这是代码:
from tkinter import *
dict = {}
Liste = ["bir","iki","üç","4",5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18]
a = 1
####### ekleme basi ##################################################
pencere = Tk()
pencere.geometry("{0}x{1}".format(100, 100))
labelFrame = LabelFrame(pencere, width = 100, height = 100)
labelFrame.pack(side="left",fill=BOTH)
canvas = Canvas(labelFrame,relief=SUNKEN)
#canvas.config(scrollregion=(0,0,300,1000)) # halloldu =)
scrollbar = Scrollbar(labelFrame)
scrollbar.config(command=canvas.yview)
canvas.config(yscrollcommand=scrollbar.set)
scrollbar.pack(side="right",fill=Y)
canvas.pack(side="left",expand=YES,fill=BOTH)
frame = Frame(canvas,width=100,height=100)
frame.pack(side="top",fill=BOTH)
canvas.create_window(0,0,window=frame, anchor="nw")
####### ekleme sonu ##################################################
bas = [0, 0, 0, 100]
for i in Liste:
dict["a%s"%a] = Label(frame, text=i) # "frame" ekledim
dict["a%s"%a].grid(row=a)
canvas["scrollregion"] = "%d %d %d %d" %(bas[0], bas[1], bas[2], bas[3])
bas[3] += 16 # "scrollregion" i dinamik olarak arttir (degistirebilirsiniz)
a += 1
mainloop()
注意:英语是我的第二语言,我不太懂,很抱歉。