我希望使用tkinter为一个小程序创建一个滚动时间线。我目前可以使用matplotlib创建图表并动态更新这些图表,但我希望能够通过传递开始和结束日期的数据来滚动时间线,类似于我所附的excel图像。
我尝试过使用ttkwidget使用tkinter内置的时间线工具,但这显示了一个滚动条和一个放大按钮,但没有这两个选项:
import tkinter as tk
from ttkwidgets import TimeLine
window = tk.Tk()
timeline = TimeLine(
window,
categories={str(key): {"text": "Category {}".format(key)} for key in range(0, 5)},
height=100, extend=True
)
menu = tk.Menu(window, tearoff=False)
menu.add_command(label="Some Action", command=lambda: print("Command Executed"))
timeline.draw_timeline()
timeline.grid()
window.after(5000, lambda: print(timeline.time))
window.mainloop()
有没有办法添加一个可拉伸的滚动条?
1条答案
按热度按时间qoefvg9y1#
Tkinter、matplotlib和ttkwidget并没有你想要的内置时间线小部件。但是,tkinter有所有的基本构件来做这件事。这只是把所有的小部件放在一个类中的问题。
这是我拼凑出来的一些东西。它并不完全适合生产,但它展示了如何很容易地将多个小部件组合成一个新的自定义小部件。