aboutsummaryrefslogtreecommitdiff
path: root/test/double-click.py
blob: a2d178e8956f581f6ee53fa6bfa1694a2fc330af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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("<Double-1>",doubleClick)  # Double-click binding doubleClick method
tree.pack()

root.mainloop()