Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 他喜欢: def _select(self, y,state=16): row = self.lists[0].nearest(y) if row in self.curselection(): # Check if the row already is in the selection self.selection_clear(row) # If it is, remove it else: self.selection_set(row) # If it isn't, add it return 'break'_Python_User Interface_Tkinter_Listbox_Tkinter Layout - Fatal编程技术网

Python 他喜欢: def _select(self, y,state=16): row = self.lists[0].nearest(y) if row in self.curselection(): # Check if the row already is in the selection self.selection_clear(row) # If it is, remove it else: self.selection_set(row) # If it isn't, add it return 'break'

Python 他喜欢: def _select(self, y,state=16): row = self.lists[0].nearest(y) if row in self.curselection(): # Check if the row already is in the selection self.selection_clear(row) # If it is, remove it else: self.selection_set(row) # If it isn't, add it return 'break',python,user-interface,tkinter,listbox,tkinter-layout,Python,User Interface,Tkinter,Listbox,Tkinter Layout,因为您还将此方法绑定到了,所以当移动到同一行时,这确实有点奇怪,因为它不断地添加和删除同一行。您可以使用下面的方法来解决这个问题,它检查您在拖动时是否已移动到另一行 self.current_row = None for l,w in lists: ... lb.bind('<B1-Motion>', lambda e, s=self: s.drag(e.y)) ... def _select(self, y,state=16): row = se

因为您还将此方法绑定到了
,所以当移动到同一行时,这确实有点奇怪,因为它不断地添加和删除同一行。您可以使用下面的方法来解决这个问题,它检查您在拖动时是否已移动到另一行

self.current_row = None

for l,w in lists:
    ...
    lb.bind('<B1-Motion>', lambda e, s=self: s.drag(e.y))
    ...

def _select(self, y,state=16):
    row = self.lists[0].nearest(y)
    if row in self.curselection():
        self.selection_clear(row)
    else:
        self.selection_set(row)
    self.current_row = row
    return 'break'

def drag(self, y):
    row = self.lists[0].nearest(y)
    if not row == self.current_row:
        self._select(y)
self.current\u行=无
对于列表中的l、w:
...
lb.bind(“”,λe,s=自:s.阻力(e.y))
...
def_选择(自身、y、状态=16):
行=自身。列表[0]。最近的(y)
如果self.curselection()中的行:
自选择\u清除(行)
其他:
自选择集(行)
self.current\u row=行
返回“中断”
def阻力(自身,y):
行=自身。列表[0]。最近的(y)
如果不是行==self.current\u行:
自我选择(y)

此代码不运行。请提供一份报告。我试着猜我该如何使用这门课,但没猜到。请同时提供使用示例。@figbeam-好的-我现在编辑了我的文章,包含了使用该类的完整代码,试图将示例减少到最少,并发现您有一个名为
index
的函数和变量。他们似乎没有干涉,但这是一件坏事…谢谢你的注意!我一定会重新命名其中一个!添加了一个答案,但更多的是评论。我包含了我收到的错误消息,我认为答案有更好的格式化机会…谢谢你的时间,figbeam!我很抱歉没有提供太多的评论。这个错误在我的系统上看不到-在这里工作正常。我希望能够在不按下任何其他按钮的情况下选择多行。顺便问一下,您看到了吗?也许值得一试,而不是写你自己的…谢谢你的链接-我还没有看到这个。如果你想对我上面的类进行一个简单的修复,我还是更愿意这样做——我正在用这段代码深入一个项目,现在不想重新构造。非常感谢@fhdrsdg!这个很好用!
# Add binding in __init()__ with the other bindings
lb.bind('<Shift-Button-1>', self.more)

# Create the function to handle <Shift-Button-1>
def more(self, event):
    first = self.lists[0].curselection()[0]     # The previous selection
    last = self.lists[0].nearest(event.y)       # Current mouse click
    self.selection_set(first, last=last)        # Set selection
def _select(self, y,state=16):
    row = self.lists[0].nearest(y)
    if state==16:self.selection_clear(0, END) # This clears the selection
    self.selection_set(row)
    ## print self.curselection()
    return 'break'
def _select(self, y,state=16):
    row = self.lists[0].nearest(y)
    if row in self.curselection(): # Check if the row already is in the selection
        self.selection_clear(row) # If it is, remove it
    else:
        self.selection_set(row) # If it isn't, add it
    return 'break'
self.current_row = None

for l,w in lists:
    ...
    lb.bind('<B1-Motion>', lambda e, s=self: s.drag(e.y))
    ...

def _select(self, y,state=16):
    row = self.lists[0].nearest(y)
    if row in self.curselection():
        self.selection_clear(row)
    else:
        self.selection_set(row)
    self.current_row = row
    return 'break'

def drag(self, y):
    row = self.lists[0].nearest(y)
    if not row == self.current_row:
        self._select(y)