aboutsummaryrefslogtreecommitdiff
path: root/test/double-click.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/double-click.py')
-rw-r--r--test/double-click.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/double-click.py b/test/double-click.py
new file mode 100644
index 0000000..a2d178e
--- /dev/null
+++ b/test/double-click.py
@@ -0,0 +1,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()