classification
Title: ttk.Combobox focus-out event inheritage
Type: behavior Stage: resolved
Components: Versions: Python 3.5
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: Nosy List: Nikolai Ehrhardt, iritkatriel, terry.reedy
Priority: normal Keywords:

Created on 2020-04-06 20:18 by Nikolai Ehrhardt, last changed 2021-10-22 19:00 by iritkatriel. This issue is now closed.

Files
File name Uploaded Description Edit
treeview_spawn_entries.png Nikolai Ehrhardt, 2020-04-06 20:18
Messages (3)
msg365878 - (view) Author: Nikolai Ehrhardt (Nikolai Ehrhardt) Date: 2020-04-06 20:18
Hi Guys,

I'm spawning entry fields in a treeview to make values editable while runtime, my codepiece:

the edit method is bind to left click:

    def edit(self, event):
        region = self.identify_region(event.x, event.y)
        if region == 'cell':
            # the user clicked on a cell

            def enter(event):
                self.set(item, column, entry.get())
                entry.destroy()

            column = self.identify_column(event.x)  # identify column
            item = self.identify_row(event.y)  # identify item
            self.parent_split = self.parent(item).split("__", 1)
            print(column, item, self.parent_split)
            if not tree_const.isEntryField(self.parent_split, column) or len(self.get_children(item)):
                return
                
            x, y, width, height = self.bbox(item, column) 
            value = self.set(item, column)
            entry = None
            if tree_const.tc_index_column_map[column] == tree_const.col_op:
                entry = ttk.Combobox(self, state="readonly", values=tree_const.combo_ops)
                entry.bind('<<ComboboxSelected>>', enter) 
                entry.set(value)
            else:
                entry = ttk.Entry(self) 
                entry.insert(0, value)  # put former value in entry
                entry.bind('<Return>', enter)  # validate with Enter     
                    
            entry.bind('<FocusOut>', enter)    
            # display the Entry   
            # create edition entry
            entry.place(x=x, y=y, width=width, height=height,
                        anchor='nw')  # display entry on top of cell
            entry.focus_set()

And now is the problem: The entries are not properly destroyed when focusing out, so I assume, that the button created for combobox, is not well connected to the focus-out event. When the button would just inherit the binding, the combobox would already disappear,while selecting.

So there is some logic missing. For destroying widget properly on focusing out.
msg366182 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2020-04-11 02:23
What OS and what tcl/tk patch version? (IDLE Help => About IDLE will show this).  3.5 only gets security patches.  On Windows, it came with a slightly older version of tk.  That might possibly be a problem.

One cannot place widgets 'in a treeview', so you are actually placing the entries or comboboxes *over* a cell of the treeview.  You are placing them, I presume, *in* the toplevel or frame also containing the treeview.  Try passing that container, instead of the treeview, as the parent.  Does the that fix your problem?  If so, please close as 'not a bug'.

Your example is too short.  It cannot be run as is.  And I do not understand the problem from your description.  If the treeview parent is not the problem, then your example is likely too long, as the treeview stuff is likely irrelevant noise.  Please repost or attach a minimal, complete and verifiable example as described in
https://stackoverflow.com/help/minimal-reproducible-example
msg404814 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-10-22 19:00
Closing as there is not enough information to understand the issue and there was not response to followup questions.
History
Date User Action Args
2021-10-22 19:00:14iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg404814

resolution: rejected
stage: resolved
2020-04-11 02:23:26terry.reedysetnosy: + terry.reedy
messages: + msg366182
2020-04-06 20:18:21Nikolai Ehrhardtcreate