如何将图像附加到 python 中 table 的单元格?
How to attach an image to a table's cell in python?
我正在使用 pygtk...所以我想将图像放入使用 gtk.Table(4,5) 创建的 table 的单元格中,数字是尺寸。
我所做的是创建按钮并将它们放入单元格中,然后加载图像并将它们附加到按钮上,但它不起作用。
我有:
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()
已解决,只需要将图像直接附加到 table,例如:
self.table.attach(image,0,1,0,1)
并且工作完美:D
我正在使用 pygtk...所以我想将图像放入使用 gtk.Table(4,5) 创建的 table 的单元格中,数字是尺寸。
我所做的是创建按钮并将它们放入单元格中,然后加载图像并将它们附加到按钮上,但它不起作用。 我有:
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()
已解决,只需要将图像直接附加到 table,例如:
self.table.attach(image,0,1,0,1)
并且工作完美:D