Skip to content

Update recipe-580794.py #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions recipes/Python/580794_Simple_multicolumn_listbox/recipe-580794.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version: 2.3
# Version: 2.4
# Author: Miguel Martinez Lopez
# Uncomment the next line to see my email
# print("Author's email: %s"%"61706c69636163696f6e616d656469646140676d61696c2e636f6d".decode("hex"))
Expand Down Expand Up @@ -137,7 +137,7 @@ def __delitem__(self, index):
def __len__(self):
return self._multicolumn_listbox.number_of_columns

def __init__(self, master, columns, data=None, command=None, sort=True, select_mode=None, heading_anchor = CENTER, cell_anchor=W, style=None, height=None, padding=None, adjust_heading_to_content=False, stripped_rows=None, selection_background=None, selection_foreground=None, field_background=None, heading_font= None, heading_background=None, heading_foreground=None, cell_pady=2, cell_background=None, cell_foreground=None, cell_font=None, headers=True):
def __init__(self, master, columns, data=None, command=None, sort=True, select_mode=None, heading_anchor = CENTER, cell_anchor=W, style=None, height=None, padding=None, adjust_heading_to_content=False, stripped_rows=None, selection_background=None, selection_foreground=None, field_background=None, heading_font= None, heading_background=None, heading_foreground=None, cell_pady=2, cell_background=None, cell_foreground=None, cell_font=None, headers=True, right_click_command=None):

self._stripped_rows = stripped_rows

Expand Down Expand Up @@ -237,6 +237,10 @@ def __init__(self, master, columns, data=None, command=None, sort=True, select_m
self._command = command
self.interior.bind("<<TreeviewSelect>>", self._on_select)

if right_click_command is not None:
self._right_click_command = right_click_command
self.interior.bind("<Button-3>", self._on_right_click)

for i in range(0, self._number_of_columns):

if sort:
Expand Down Expand Up @@ -443,6 +447,12 @@ def _on_select(self, event):
data_row = self.item_ID_to_row_data(item_ID)
self._command(data_row)

def _on_right_click(self, event):
item_ID = event.widget.identify_row(event.y)
data_row = self.item_ID_to_row_data(item_ID)
if data_row:
self._right_click_command(data_row)

def item_ID_to_row_data(self, item_ID):
item = self.interior.item(item_ID)
return item["values"]
Expand Down Expand Up @@ -543,11 +553,16 @@ def on_select(data):
print("called command when row is selected")
print(data)
print("\n")


def on_right_click(data):
print("called command when row is right clicked")
print(data)
print("\n")

def show_info(msg):
messagebox.showinfo("Table Data", msg)

mc = Multicolumn_Listbox(root, ["column one","column two", "column three"], stripped_rows = ("white","#f2f2f2"), command=on_select, cell_anchor="center")
mc = Multicolumn_Listbox(root, ["column one","column two", "column three"], stripped_rows = ("white","#f2f2f2"), command=on_select, cell_anchor="center", right_click_command=on_right_click)
mc.interior.pack()

mc.insert_row([1,2,3])
Expand Down Expand Up @@ -607,3 +622,4 @@ def show_info(msg):
show_info("mc.row[0].update([2,4,5])")

root.mainloop()