Selection from a Treeview automatically converts string numbers to integers Selection from a Treeview automatically converts string numbers to integers tkinter tkinter

Selection from a Treeview automatically converts string numbers to integers


By duplicating data from values into text (when adding new item to the tree) and later reading from text (instead of values), would allow to overcome this limitation.

from tkinter import Tkfrom tkinter import Framefrom tkinter import Buttonimport tkinter.ttk as ttk# print(TkVersion) # 8.6def edit(tree):    if len(tree.selection()) == 1:        selected_item = tree.item(tree.selection())        #print(selected_item['values'][0])        print(selected_item['text'])    else:        print('please select item')gui = Tk()container = Frame(gui)container.pack(expand=True, fill='both')edit_button = Button(gui, text='Edit', command=lambda: edit(tree))edit_button.pack(fill='x')tree = ttk.Treeview(container, show='headings')col_names = ['Contact No.']tree['columns'] = col_namesfor col_name in col_names:    tree.heading(col_name, text=col_name)phone_nums = ['01234567895']for phone_num in phone_nums:    tree.insert('', 'end', text=phone_num, values=phone_num)tree.pack(expand=True, fill='both')gui.mainloop()