【发布时间】:2012-02-11 22:27:57
【问题描述】:
使用this stackoverflow post 中的代码,我对其稍作更改,为每个其他检查按钮添加背景颜色,并将宽度设置为填充 Text 小部件的宽度。但是,发生这种情况时,我无法使用鼠标滚轮滚动。我必须抓住滚动条。
有没有更好的方法可以正常滚动?这是我的代码:
import Tkinter as tk
root = tk.Tk()
vsb = tk.Scrollbar(orient="vertical")
text = tk.Text(root, width=40, height=20, yscrollcommand=vsb.set)
vsb.config(command=text.yview)
vsb.pack(side="right",fill="y")
text.pack(side="top",fill="both",expand=True)
for i in range(1000):
bg = 'grey'
if i % 2 == 0:
bg = 'white'
cb = tk.Checkbutton(text="checkbutton #%s" % i, bg=bg, width=35, justify=tk.LEFT)
text.window_create("end", window=cb)
text.insert("end", "\n") # to force one checkbox per line
root.mainloop()
【问题讨论】: