在 tkinter 中滚动笔记本标签

时间:2021-04-07 11:25:05

标签: python tkinter ttk

有没有办法在 tkinter 中滚动 Notebook 选项卡?

代码如下:

from tkinter import *
from tkinter import ttk

app_width = 500
app_height = 560

root = Tk()
root.geometry(f"{app_width}x{app_height}")

def create_new_tab(frame , text):
    tab_container.add(frame , text=text)

def scroll_right():
    # Code to scroll the tabs to the right
    pass

def scroll_left():
    # Code to scroll the tabs to the left
    pass

tab_container = ttk.Notebook(root , width = app_width , height = app_height)
tab_container.place(x = 0 , y = 0)
tab_container.pack_propagate(0)

for i in range(1, 50):
    temp_frame = Frame(tab_container, width=1000, height=1000)
    temp_frame.pack_propagate(0)
    Text(temp_frame).place(x = 0 , y = 0)
    create_new_tab(temp_frame, f"Tab {i}")

right_button = Button(root , text = "Scroll Right" , command = scroll_right)
right_button.place(x=150 , y = 520)

left_button = Button(root , text = "Scroll Left" , command = scroll_left)
left_button.place(x=250 , y = 520)

mainloop()

在这里,我想在点击按钮时向左或向右滚动 Notebook 的标签。

有没有办法在 tkinter 中实现这一点?

如果有人能帮助我就好了。

(我在 stackoverflow 上看到了很多与此相关的问题,但似乎都没有。)

0 个答案:

没有答案