是否可以這樣做:
用ttk.Notebook部件?
uj5u.com熱心網友回復:
是的,這是有可能的。你必須將B1-Motion系結到一個函式,然后使用notebook.index("@x,y")來獲得滑鼠位置上的標簽的索引。然后你可以使用notebook.insert()來在一個特定的位置插入。
import tkinter as tk
from tkinter import ttk
def reorder(event)。
try:
index = notebook.index(f"@{event.x},{event.y}"/span>)
notebook.insert(index, child=notebook.select())
except tk.TclError:
pass[/span
root = tk.Tk()
root.geometry("500x500")
notebook = ttk.Notebook(root)
notebook.pack(fill="both", expand=True)
notebook.bind("<B1-Motion>"/span>, reorder)
frame1 = ttk.Frame(notebook)
frame2 = ttk.Frame(notebook)
frame1.pack(fill='both', expand=True)
frame2.pack(fill='both', expand=True)
notebook.add(frame1, text='Stackoverflow')
notebook.add(frame2, text='Github')
root.mainloop()
輸出:
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/330604.html
標籤:


