Tkinter Treeview selection

半城伤御伤魂 提交于 2019-12-12 23:47:23

问题


from Tkinter import *
from ttk import *
import tkMessageBox

class Application(Frame) :
    def selected(self):
        curItem = self.tree.focus();
        print self.tree.item(curItem)['values'][0]
        self.quit()

    def __init__(self,master = None):
        Frame.__init__(self, master)
        self.grid()

        tree = self.tree = Treeview(self,columns=('Name','Description'),show="headings",selectmode='browse')
        tree.heading("Name", text="Name")
        tree.heading("Description", text="Description")
        tree.grid(padx = 30)

        i = tree.insert('','end',values = ['0353','567'])
        tree.insert(i,'end',values = ['03535','567'])
        Button(self,text = "Submit",command = self.selected).grid()


root = Tk()
app = Application()
app.master.title("Tree view")
app.master.minsize(500, 400)
app.master.protocol(name = "WM_DELETE_WINDOW",func=app.master.quit)

app.mainloop()
root.destroy()

When I try to select "0353" in the tree view and submit it is printing '353' instead of 0353. I want the output to be "0353". I am using python 2.7

来源:https://stackoverflow.com/questions/39067164/tkinter-treeview-selection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!