【问题标题】:How to attach an image to a table's cell in python?如何将图像附加到python中的表格单元格?
【发布时间】:2016-05-02 01:25:48
【问题描述】:

我正在使用 pygtk...所以我想将图像放在使用 gtk.Table(4,5) 创建的表格的单元格中。数字是尺寸。

我所做的是创建按钮并将它们放入单元格中,然后我加载图像并将它们附加到按钮上,但它不起作用。 我有:

class D:

    def __init__(self):

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.set_border_width(300)

        self.table = gtk.Table(4, 5, True)
        self.window.add(self.table)

        button = gtk.Button("unicorn")
        image = gtk.Image()
        image.set_from_file("unicorn.png")
        image.show()
        button.set_image(image)
        button.set_size_request(20,20)

        self.table.attach(button, 0, 1, 0, 1)
        button.show()
        self.table.show()
        self.window.show_all()

    def main():
        gtk.main()
        return 0

    if __name__ == "__main__":
        D()
        main()

【问题讨论】:

    标签: python python-2.7 interface pygtk


    【解决方案1】:

    已解决,只需要将图像直接附加到表格中即可:

        self.table.attach(image,0,1,0,1)
    

    完美运行:D

    【讨论】:

      猜你喜欢
      • 2011-09-10
      • 2021-01-24
      • 2011-07-09
      • 2016-09-13
      • 2018-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多