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

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

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

问题

要获取特定列的最后一项数值您可以使用以下代码

```python
for child in OUT_DC_Level_data_table.get_children():
    item_values = OUT_DC_Level_data_table.item(child)['values']
    get_latest_value_OUT_DC_level_frozen = int(item_values[1][-1])
    get_latest_value_OUT_DC_level_chill = int(item_values[2][-1])
    get_latest_value_OUT_DC_level_dry = int(item_values[3][-1])

<details>
<summary>英文:</summary>

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

    for child in OUT_DC_Level_data_table.get_children():
            item_values = OUT_DC_Level_data_table.item(child)[&#39;values&#39;]
            get_latest_value_OUT_DC_level_frozen = int(OUT_DC_Level_data_table.item(child)[&#39;values&#39;][1][-1])
            get_latest_value_OUT_DC_level_chill = int(OUT_DC_Level_data_table.item(child)[&#39;values&#39;][1][-1])
            get_latest_value_OUT_DC_level_dry = int(OUT_DC_Level_data_table.item(child)[&#39;values&#39;][1][-1])

</details>


# 答案1
**得分**: 1

首先,您获取最后一项的 *项目 ID*,然后使用 `.set(item_id, column_name)` 获取所需的值:

```python
# 获取最后一项的项目 ID
item_id = OUT_DC_Level_data_table.get_children()[-1]
# 例如,获取列 "frozen" 的最新值
get_latest_value_OUT_DC_level_frozen = int(OUT_DC_Level_data_table.set(item_id, "frozen"))
# 类似地获取其他列的值
英文:

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

# get the item ID of the last item
item_id = OUT_DC_Level_data_table.get_children()[-1]
# get the value of column &quot;frozen&quot; for example
get_latest_value_OUT_DC_level_frozen = int(OUT_DC_Level_data_table.set(item_id, &quot;frozen&quot;))
# 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:

确定