gpt4 book ai didi

python - 禁用 wx.ComboBox 小部件上的鼠标滚轮事件

转载 作者:行者123 更新时间:2023-12-01 04:29:55 27 4
gpt4 key购买 nike

我有一个带有组合框的wx.Frame。当在组合框中进行选择时,将调用特定函数。

我对组合框产生了不良影响。当 ComboBox 具有焦点时,鼠标滚轮的任何移动都会更改选择,从而触发不同的功能。

在实践中,很难记住你必须将小部件置于焦点之外才能“保存”你原来的选择,因此,由于触发的功能需要每隔几秒钟才能完成,GUI 的可用性不好。

我尝试使用捕获鼠标事件但无济于事

self.Bind(wx.EVT_MOUSEWHEEL, self.donothing, self.mycombobox)

防止鼠标信号影响组合框的最佳程序是什么?

编辑
如果您想使用代码,可以执行和测试以下代码。只需执行,用鼠标进行选择,然后播放鼠标滚轮即可。我不想改变选择。我无法捕获由鼠标滚轮发出的事件,无论它是什么。

import wx

class Myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
pan = wx.Panel(self)

self.cbx = wx.ComboBox(pan, -1, pos=(10,30),
choices=["SEARCH", "SELECT", "PASS"],
style=wx.CB_DROPDOWN )

self.cbx_2 = wx.ComboBox(pan, -1, pos=(10,60),
choices=["LOOK", "GO", "FILL"],
style=wx.CB_DROPDOWN )

self.Bind(wx.EVT_MOUSEWHEEL, self.do_nothing) # to no avail
self.Bind(wx.EVT_COMBOBOX, self.on_selection, self.cbx)
self.Bind(wx.EVT_COMBOBOX, self.on_selection_2, self.cbx_2)

def on_selection(self, evt):
"""I do not want this to be executed inadvertently when
moving mousewheel"""
print self.cbx.GetStringSelection()
#evt.Skip(False) # this is the default behavior anyway

def on_selection_2(self, evt):
"""this is another combobox. dont mind if mouse move it or not"""
print self.cbx.GetStringSelection()

def do_nothing(self, evt):
""
print 'on events pit' # never catched !!!
#evt.Skip(False) # this is the default behavior anyway


if __name__ == "__main__":
App = wx.PySimpleApp()
Myframe().Show()
App.MainLoop()

最佳答案

需要另一双眼睛。

import wx

class Myframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None)
pan = wx.Panel(self)
self.cbx = wx.ComboBox(pan, -1, pos=(10,30),
choices=["SEARCH", "SELECT",
"PASS", "LOG", "DATABASE"],
style=wx.CB_DROPDOWN )
self.cbx_2 = wx.ComboBox(pan, -1, pos=(10,60),
choices=["LOOK", "GO", "FILL"],
style=wx.CB_DROPDOWN )

self.cbx.Bind(wx.EVT_MOUSEWHEEL, self.do_nothing)
self.cbx.Bind(wx.EVT_COMBOBOX, self.on_selection)
self.cbx_2.Bind(wx.EVT_MOUSEWHEEL, self.do_nothing)
self.cbx_2.Bind(wx.EVT_COMBOBOX, self.on_selection_2)

def on_selection(self, evt):
"""I do not want this to be executed inadvertently when
moving mousewheel"""
print self.cbx.GetStringSelection()

def on_selection_2(self, evt):
"""this is another combobox. dont mind if mouse move it or not"""
print self.cbx.GetStringSelection()

def do_nothing(self, evt):
print 'on events pit'

if __name__ == "__main__":
App = wx.PySimpleApp()
Myframe().Show()
App.MainLoop()

self.Bindself.widget.Bind 差异为 explained in the wxPyWiki

关于python - 禁用 wx.ComboBox 小部件上的鼠标滚轮事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32522584/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com