[英]Modify the tag of the selected row in python tkinter treeview
我添加了以下代碼(取自這篇文章),但是我沒有得到想要的解決方案。
def change_colour():
trv.set(trv.selection()[0],0,tags='changed_tag') #this causes problem
trv.tag_configure("changed_tag",foreground="blue",background="yellow")
執行時出現此錯誤(來自函數的第一行):
TypeError: set() got an unexpected keyword argument 'tags'
我的目標是更改所選項目的標簽(在樹視圖中),所以它的顏色會改變。
對於有同樣問題的任何人,我自己都找到了解決方案:
def high_target():
selected_item = trv.selection()[0]
trv.item(selected_item, tags='changed_tag')
trv.tag_configure("changed_tag",foreground="blue",background="yellow")
我認為你的代碼應該是這樣的(雖然沒有測試):
def change_colour(iid):
trv.item(iid, tags="changed_tag")
trv.tag_configure("changed_tag", foreground="blue", background="yellow")
在您使用 trv.insert 創建 treeview 項目的位置,將trv.insert
返回的值trv.insert
在變量中並將其作為參數傳遞給change_colour
。 例子:
iid = trv.insert("", "end", values=("a", "b", "c"))
change_colour(iid)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.