在python gtk3中拖动时按下多个按钮

时间:2014-08-20 02:26:21

标签: python gtk3

我希望能够点击并拖动按钮,并为所有按钮获得button-press-event

from gi.repository import Gtk

class mainWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Main")

        self.tablex = 10
        self.tabley = 10



        self.resize(800,600)

        scroll = Gtk.ScrolledWindow()
        self.table = Gtk.Table(self.tablex, self.tabley, True)
        align = Gtk.Alignment(xscale = 0,yscale = 0,xalign = 0,yalign = 0)
        align.add(self.table)
        scroll.add_with_viewport(align)
        self.table.set_homogeneous(True)
        self.fillTable()
        self.add(scroll)

    def fillTable(self):
        self.tableList = []
        for x in range(self.tablex):
            self.tableList.append([])
            for y in range(self.tabley):
                self.tableList[x].append({"eBox" : Gtk.EventBox(), "image" : Gtk.Image(), "coords" : (x,y)})
                self.tableList[x][y]["image"].set_from_stock(Gtk.STOCK_ADD, 5)
                self.tableList[x][y]["eBox"].add(self.tableList[x][y]["image"])
                self.tableList[x][y]["eBox"].connect("button-press-event", self.change, (x,y))
                self.tableList[x][y]["eBox"].set_size_request(34,34)
                self.table.attach(self.tableList[x][y]["eBox"],x,x+1,y,y+1)

    def change(self,box, event,  coords):
        x = coords[0]
        y = coords[1]
        self.tableList[x][y]["image"].set_from_stock(Gtk.STOCK_APPLY, 5)

main = mainWindow()

main.connect("delete-event", Gtk.main_quit)

main.show_all()
Gtk.main()

喜欢使用:

self.tableList[x][y]["eBox"].connect("enter-notify-event", self.change, (x,y))

而不是:

self.tableList[x][y]["eBox"].connect("button-press-event", self.change, (x,y))

仅当我按住鼠标按钮

0 个答案:

没有答案