获取特定列中的最后一项在tkinter python中的方法是什么?

huangapple go评论93阅读模式
英文:

How to get last item of a specific column in tkinter python?

问题

  1. 要获取特定列的最后一项数值您可以使用以下代码
  2. ```python
  3. for child in OUT_DC_Level_data_table.get_children():
  4. item_values = OUT_DC_Level_data_table.item(child)['values']
  5. get_latest_value_OUT_DC_level_frozen = int(item_values[1][-1])
  6. get_latest_value_OUT_DC_level_chill = int(item_values[2][-1])
  7. get_latest_value_OUT_DC_level_dry = int(item_values[3][-1])
  1. <details>
  2. <summary>英文:</summary>
  3. So I want to get the last item value of a specific column. How do you do this? All I know is to get all value of tkinter treeview. I have tried everything, but I am still clueless. The code I did below get error *TypeError: &#39;int&#39; object is not subscriptable*. I want the data of the get_latest_value to be able to make calculation, such as get_latest_value_frozen * 30
  4. for child in OUT_DC_Level_data_table.get_children():
  5. item_values = OUT_DC_Level_data_table.item(child)[&#39;values&#39;]
  6. get_latest_value_OUT_DC_level_frozen = int(OUT_DC_Level_data_table.item(child)[&#39;values&#39;][1][-1])
  7. get_latest_value_OUT_DC_level_chill = int(OUT_DC_Level_data_table.item(child)[&#39;values&#39;][1][-1])
  8. get_latest_value_OUT_DC_level_dry = int(OUT_DC_Level_data_table.item(child)[&#39;values&#39;][1][-1])
  9. </details>
  10. # 答案1
  11. **得分**: 1
  12. 首先,您获取最后一项的 *项目 ID*,然后使用 `.set(item_id, column_name)` 获取所需的值:
  13. ```python
  14. # 获取最后一项的项目 ID
  15. item_id = OUT_DC_Level_data_table.get_children()[-1]
  16. # 例如,获取列 "frozen" 的最新值
  17. get_latest_value_OUT_DC_level_frozen = int(OUT_DC_Level_data_table.set(item_id, "frozen"))
  18. # 类似地获取其他列的值
英文:

First you get the item ID of the last item, then use .set(item_id, column_name) to get the required values:

  1. # get the item ID of the last item
  2. item_id = OUT_DC_Level_data_table.get_children()[-1]
  3. # get the value of column &quot;frozen&quot; for example
  4. get_latest_value_OUT_DC_level_frozen = int(OUT_DC_Level_data_table.set(item_id, &quot;frozen&quot;))
  5. # get values of other columns similarly

huangapple
  • 本文由 发表于 2023年5月17日 16:57:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76270273.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定