Getting Tkinter listbox item when hit Button-1 - python

After creating a simple window/widget layout with Page (page.sourceforge.net)
I found that the listbox curselection() call returns the proper index when releasing Button-1.
When hit, it returns the previous index (the item which we just leave).
Becasue of some timer activities I'd like to get the clicked index at click-time, instead of release-time. Can somebody help me how could I do that? Thank you

Bind to the event <<ListboxSelect>> instead of <1>, this event will fire after the current selection has been updated.
If you genuinely need for the binding to work literally on a press of the mouse button you will have to rearrange the order of the bind tags for the widget.

Related

wxpython call a function when focus of TextCtrl changes

Morning, I would like to call a function in my GUI in the event that the content of a TextCtrl is changed. Only after the user leaves the TextCtrl object though, not during editing.
Please can you help me find the right event handler to use, I'm very new to wxpython and I can't even find a list of allowable events.
Many thanks
You can bind the TextCtrl to wx.EVT_TEXT to capture changes to the value and wx.EVT_KILL_FOCUS to trigger an even when the focus changes. Alternatively you could bind it to wx.EVT_SET_FOCUS and save the current TextCtrl value and also bind to it wx.EVT_KILL_FOCUS to and compare the new value to see if it's changed.
------- EDIT -------
WxFormBuilder is fantastic tool for quickly creating basic UIs. It will also show you every event that you can bind to a widget by clicking on the 'events'` tab.

PyQt: How to determine, which mouse button is pressed and over which QTableView's cell at the same time?

I write a PyQt application with QTableView, which should insert a new column in response to a left click and delete a column in response to right mouse click on its cells.
What signal should I connect handlers to? If I use QAbstractItemView.clicked, I can receive the index of column, but can't determine the mouse button, cause it doesn't receive the event.
One the other hand, if I use QAbstractScrollArea.mousePressEvent, I can get event.button(), but it's not clear, how to recover the cell's index.
Qt kinda remind of Schrödinger's indeterminacy here :)
You can get the state of the mouse buttons with QApplication.mouseButtons:
buttons = QtGui.qApp.mouseButtons()
With mousePressEvent, you can use QAbstractItemView.indexAt to get the index:
index = tableview.indexAt(event.pos())

wxpython SearchCtrl two events triggered

I am using a SearchCtrl with a dropdown menu and I'm having some trouble with the events. When I click the little arrow next to the search button, the EVT_SEARCHCTRL_SEARCH_BTN is triggered, which is not what I want. I only want the EVT_MENU_RANGE to be triggered after I clicked an item, and not also the EVT_SEARCHCTRL_SEARCH_BTN before i click it.
self.search_ctrl = wx.SearchCtrl(self.panel_1, -1,
style=wx.TE_PROCESS_ENTER)
self.search_menu = wx.Menu()
self.search_items = {"text1":"value1", "text2":"value2"}
for txt in self.search_items:
self.search_menu.Append(-1, txt)
self.search_ctrl.SetMenu(self.search_menu)
self.Bind(wx.EVT_SEARCHCTRL_SEARCH_BTN, self.search, self.search_ctrl)
self.Bind(wx.EVT_MENU_RANGE, self.onSearchMenu)
Although I should probably add id's to the menu bind, this isn't causing the problem. The code works as expected when I comment out the search button bind.
UPDATE
Apparently this isn't a problem, but a 'feature' of the searchctrl. I tried the wxpython demo and the menu also showed up if I just clicked the search button, and not the arrow. It is apparently one button, instead of the two i thought it was.
Is there a way to accomplish my original request? Do i have to manually modify a textctrl, or is there an other solution?
All the examples I've seen suggest you need to specify a range of IDs when you call your menu bind.
Maybe by default it binds to something unexpected... ?
Edit - In light of your update, it seems likely that you're going to need to make a custom control to me..

Buttons in vizard

I am developing a GUI in Vizard in which i am using radio buttons to select correct options, but I have a problem that I cannot solve.
In every group of radio buttons the 1st button always appears to be selected, but is actually not selected. The only way to select it is by choosing another button and then choosing the 1st button again.
Does anyone know how to solve this? I would like that in the beginning none of the buttons are selected.
I don't know Vizard but radio buttons probably have a method or another way of deselecting them similar to radiobutton.deselect() method of Tkinter. Have you looked at their documentation?
Also someone have done this trick, may be you should try it:
Create another radio button in that group, let it be selected by default and make it invisible
QuestionBox = vizinfo.add("") #Add the vizinfo object
#Create an invisible Radio button to be the default selected one, so that one of the visible ones must be chosen by the user
invisibleRadio = QuestionBox.add(viz.RADIO, 0, "")
invisibleRadio.visible(0) #invisible
source: http://forum.worldviz.com/showthread.php?t=1611

Python/Tkinter: bind to event related to currently selected menu item

Wondering if there's a menu event I can bind to that's related to the currently selected menu item? By menu item I mean the items that show up in a popup menu like New, Open, Save, etc.
Use case: I would like to update a statusbar area of our application with a description of the currently selected menu item.
Any ideas appreciated.
Thank you,
Malcolm
You need to bind to the <<MenuSelect>> event.
There's an <Enter> event that is triggered when the mouse pointer enters a widget's space. Depending on how you're building your menu, you may be able to use it.
See http://www.pythonware.com/library/tkinter/introduction/events-and-bindings.htm for more

Categories

Resources