ism*_*lik 2 canvas tkinter scrollbar python-3.x
我用Python编写了一个程序。但是我想知道是否有更短的方法可以做到这一点。特别是关于“画布”,“框架”,“ 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()
Run Code Online (Sandbox Code Playgroud)
注意:英语是我的第二语言,我不太了解,很抱歉。
设置滚动区域的典型方法是将其设置为画布中所有内容的边界框,可以使用bbox方法检索该边界框,并为其赋予文字字符串"all"
canvas.configure(scrollregion = canvas.bbox("all"))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7477 次 |
| 最近记录: |