diff options
author | Vikas Kushwaha <dev@vikas.rocks> | 2024-11-21 13:23:10 +0530 |
---|---|---|
committer | Vikas Kushwaha <dev@vikas.rocks> | 2024-11-21 13:23:10 +0530 |
commit | 8f0751170385989677392f806762a211f99412ef (patch) | |
tree | f09ad917798fa313edb77925a1ddbc6de8fb37ce /test/double-click.py |
First Commit
Diffstat (limited to 'test/double-click.py')
-rw-r--r-- | test/double-click.py | 34 |
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() |