from tkinter import * from tkinter import messagebox from tkinter.ttk import * def doubleClick(event): e = event.widget # Get event controls iid = e.identify("item",event.x,event.y) # Get the double-click item id state = e.item(iid,"text") # Get state city = e.item(iid,"values")[0] # Get city outputStr = "{0} : {1}".format(state,city) # Formatting messagebox.showinfo("Double Clicked",outputStr) # Output root = Tk() root.title("ch18_12") stateCity = {"Illinois": "Chicago", "California": "Los Angeles", "Texas": "Houston", "Washington": "Seattle", "Jiangsu": "Nanjing", "Shandong": "Qingdao", "Guangdong": "Guangzhou", "Fujian": "Xiamen"} # Create Treeview tree = Treeview(root,columns=("cities")) # Create column headings tree.heading("#0",text="State") # Icon bar tree.heading("cities",text="City") # Format field tree.column("cities",anchor=CENTER) # Create Content for state in stateCity.keys(): tree.insert("",index=END,text=state,values=stateCity[state]) tree.bind("",doubleClick) # Double-click binding doubleClick method tree.pack() root.mainloop()