有沒有辦法確定哪個專案在tkinter給定它們各自的 id 的畫布的顯示順序上是最上面的?
uj5u.com熱心網友回復:
您可以使用canvas.find_all()獲取所有專案 ID 并根據檔案:“專案按堆疊順序回傳,最低專案在前”。
下面是一個在檢查串列中查找最頂層專案的示例:
check_ids = [1, 3, 5, 7]
all_ids = list(canvas.find_all())
# remove item IDs in all_ids that are not in check_ids
for x in all_ids[:]:
if x not in check_ids:
all_ids.remove(x)
# now all_ids contains only ID from check_ids sorted by stacking order
# so the last item ID is the topmost item in the list
topmost = all_ids[-1]
print(topmost)
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/441023.html
下一篇:tkinter圓形按鈕有白色邊框
