使用在this stackoverflow post中找到的代码,我稍微改变了它以包含每个其他checkbutton的背景色并设置宽度以填充Text小部件的宽度。但是,发生这种情况时,我无法使用鼠标滚轮进行滚动。我必须抓住滚动条。Tkinter checkbuttons在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()
这似乎没有帮助吗?至少不是这个例子... – intargc 2012-01-27 18:27:08