wxPyhton通过按住Shi在wxGrid中选择更多行

2024-10-01 22:34:10 发布

您现在位置:Python中文网/ 问答频道 /正文

我想让用户在网格中选择更多的行,方法是按住Shift按钮,同时单击用户要选择的第一行和最后一行。 我已经测试过了:

    def OnRangeSelect(self, event):
    if event.Selecting():
        top = event.GetTopRow()
        bottom = event.GetBottomRow()
        while top <= bottom:
            print bottom
            self.myGrid.SelectRow(top, True)
            top += 1
    event.Skip()

还有这个:

^{pr2}$

但总是这样。。。在

但也有一些棘手的事情发生:
1) 函数正在调用->;好的
2) 它不选择行,尽管它进入循环(使用PyDev调试器测试)
3) 如果我选择第3行作为顶行,第6行作为底行,wxPython选择从0到6的所有行。。。在

我不知道该怎么办…
Python版本:2.7
wxPython 2.9版


Tags: 方法用户selfevent网格ifshifttop
1条回答
网友
1楼 · 发布于 2024-10-01 22:34:10

参考此代码可能有助于:

import wx
import wx.grid as gridlib


class MyGrid(gridlib.Grid):

    def __init__(self, parent):
        """Constructor"""
        gridlib.Grid.__init__(self, parent)
        self.CreateGrid(12, 8)




        self.Bind(gridlib.EVT_GRID_RANGE_SELECT, self.OnshiftSelect)




    def OnshiftSelect(self, evt):
        if evt.Selecting():
            msg = 'Selected'
        else:
            msg = 'Deselected'
        print "OnshiftSelect: %s  top-left %s, bottom-right %s\n" % (msg, evt.GetTopLeftCoords(),
                                                                     evt.GetBottomRightCoords())
        evt.Skip()




class MyForm(wx.Frame):

    def __init__(self):
        """Constructor"""
        wx.Frame.__init__(self, parent=None, title="Grid events")
        panel = wx.Panel(self)

        myGrid = MyGrid(panel)

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(myGrid, 1, wx.EXPAND)
        panel.SetSizer(sizer)

if __name__ == "__main__":
    app = wx.PySimpleApp()
    frame = MyForm().Show()
    app.MainLoop()

相关问题 更多 >

    热门问题