小编sam*_*tun的帖子

python tkinter树获取所选项目值

我只是从python 3.4中的一个小tkinter树程序开始.

我坚持返回所选行的第一个值.我有多行有4列,我在左键单击一个项目时调用一个函数:

tree.bind('<Button-1>', selectItem)
Run Code Online (Sandbox Code Playgroud)

功能:

def selectItem(a):
    curItem = tree.focus()
    print(curItem, a)
Run Code Online (Sandbox Code Playgroud)

这给了我这样的东西:

I003 <tkinter.Event object at 0x0179D130>
Run Code Online (Sandbox Code Playgroud)

看起来所选项目已正确识别.我现在需要的是如何获得行中的第一个值.

树创作:

from tkinter import *
from tkinter import ttk

def selectItem():
    pass

root = Tk()
tree = ttk.Treeview(root, columns=("size", "modified"))
tree["columns"] = ("date", "time", "loc")

tree.column("date", width=65)
tree.column("time", width=40)
tree.column("loc", width=100)

tree.heading("date", text="Date")
tree.heading("time", text="Time")
tree.heading("loc", text="Loc")
tree.bind('<Button-1>', selectItem)

tree.insert("","end",text = "Name",values = ("Date","Time","Loc"))

tree.grid()
root.mainloop()
Run Code Online (Sandbox Code Playgroud)

python tree row tkinter

9
推荐指数
1
解决办法
3万
查看次数

javascript - 在字符串中查找类型的最后一个字符

我在网站上有一些自动生成文件夹的名称.

它们的名字如下:

"folder_photos_today_1"
"folder_photos_yesterday_2"
"folder_photos_future_3"
...
"folder_potos_more_11"
Run Code Online (Sandbox Code Playgroud)

每个名称末尾的数字是文件夹的ID,由插件生成.

现在我想显示这些文件夹名称,如:

"folder photos today"
"folder photos yesterday"
Run Code Online (Sandbox Code Playgroud)

使用javascript转换名称(pureJS或jQuery,无所谓)我想到找到_名称中的最后一个并删除它以及之后的所有内容.然后搜索其他_并用空格替换它们.

遇到的问题: 如何用JS 找到一种类型的最后一个字符(最后一个_)

javascript string jquery text replace

1
推荐指数
1
解决办法
1732
查看次数

标签 统计

javascript ×1

jquery ×1

python ×1

replace ×1

row ×1

string ×1

text ×1

tkinter ×1

tree ×1