我已经尝试过创建一个可滚动的画布并将小部件设为子级。它似乎不起作用。这是我正在使用的代码:
#CALENDAR
##Setup
container = Frame(root)
container.pack(fill=X)
scrollable_canvas = Canvas(container)
scrollbar = Scrollbar(container)
scrollbar.pack( side = RIGHT, fill = Y)
scrollbar.config(command = scrollable_canvas.yview)
scrollable_canvas.config(yscrollcommand=scrollbar.set)
scrollable_canvas.pack(fill=X)
##Class
class Event:
def __init__(self, master, date, name, start, end, desc):
self.button = Button(master, text='{}\n{}-{}'.format(name,start,end),command=lambda:self.description(desc))
self.date = date
def current(self):
pass
def description(self, desc):
top = Toplevel()
top.title("Description:")
label = Label(top, text = desc)
button = Button(top, text = "Exit",command = top.destroy)
label.pack()
button.pack()
top.mainloop()
def place(self):
self.button.pack(fill=X)
for i in range(100):
Event(container, today, 'IA{}'.format(i), '14:00', '17:30', 'Wegwerqwqrgwrqethq34t32tretr3wrer\nweqre wqewrwer2er\newrqewrewreregr q3e2ergwe efer\nrweffeqfwrbfrweqfwwrfewfbd\nhgdfhhfdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd\n\n\n\n\n\\n\n\n?').place()
如您所见,如果您要运行它,所有按钮都会弹出,滚动条也会弹出,但滚动条对按钮没有影响。