3

A similar question was asked back in '15 Make Tkinter Notebook be Draggable to Another View but that was a while ago and that also asked about re-binding the window.

I was wondering how I would make a notebook draggable, even if is just to reorder the tabs.

Any advice would be helpful and please let me know if this question has been answered

Supamee
  • 615
  • 5
  • 15
  • 2
    Tab dragging has been implemented in tcl: https://wiki.tcl-lang.org/page/ttk::notebook, https://wiki.tcl-lang.org/page/Drag+and+Drop+Notebook+Tabs. It can either be translated to python or evaluated through `.tk.eval()`. – j_4321 Dec 05 '18 at 08:35
  • 3
    And if you are interested in adding animations to the dragging (seeing the dragged tab move), I did this kind of thing but for dragging columns/rows of a treeview [here](https://github.com/RedFantom/ttkwidgets/blob/master/ttkwidgets/table.py). Maybe it can help. – j_4321 Dec 05 '18 at 08:42
  • @j_4321 could you add those as answers? Could you also give more detail with `.tk.eval`? – TRCK Jun 09 '22 at 21:05

1 Answers1

2

Tab dragging has been implemented in TCL: https://wiki.tcl-lang.org/page/ttk::notebook, https://wiki.tcl-lang.org/page/Drag+and+Drop+Notebook+Tabs. It can either be translated to python or evaluated through .tk.eval().

For the second solution, one can put the TCL tab dragging code from the first link (except the last block which creates an example notebook) in a string and evaluate it with root.tk.eval(TCL_CODE). Subsequently created notebooks will have tab dragging:

import tkinter as tk
from tkinter import ttk

tcl_code = """
put here the code from the dragging tab code section of https://wiki.tcl-lang.org/page/ttk::notebook
"""

root = tk.Tk()
root.tk.eval(tcl_code)

nb = ttk.Notebook(root)
nb.pack()
for i in range(10):
    nb.add(ttk.Frame(nb, width=100, height=100), text=f"Tab {i}")

root.mainloop()

I also implemented tab dragging with animations (seeing the dragged tab move) as part of a larger project, the source code is available here.

j_4321
  • 15,431
  • 3
  • 34
  • 61