简体   繁体   中英

How can I tell if the drop-down list of a `ComboBox` is open?

In wxPython, how can I tell what is the state of the drop-down list of a ComboBox , that is, is it open or closed?

I'm trying to implement a ComboBox that allows the user to delete a value from the list by opening the drop-down list, selecting an item, and pressing delete ( Edit: when I say selecting here I mean just highlighting an item, without clicking it yet, so the drop-down list remains open).
I can bind the delete key, and I know how to delete an item, the only problem is the delete key has a different function if the drop-down list is closed (its usual function in the text field), which I want to preserve.

Use EVT_COMBOBOX. That fires when the user selects something from the list. I would store the selection in an instance variable (like self.currentSelection). You may want to store the previous selection too. Then when the user presses "delete" you can delete the new selection or show a prompt asking them if they really want to delete that item.

UPDATE: As mentioned in the comments, I think ComboCtrl is a good alternative. You can find examples of its usage at the following:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM