Python GTK中的可单击图标

Python GTK中的可单击图标,python,gtk,pygtk,Python,Gtk,Pygtk,有人知道如何在PyGTK中创建带有自定义图标的自定义按钮吗? 我想用python GTK制作一个类似于设置菜单或控制面板的程序。我知道PyGTK有取消、退出和ok等库存按钮;但我无法更改这些按钮的标签或图标 您可以在屏幕上放置一个按钮,并在其中放置任何图像 #!/usr/bin/env python # -*- coding: utf-8 -*- # # test_icon.py # # Copyright 2015 John Coppens <john@jcoppens.com&

有人知道如何在PyGTK中创建带有自定义图标的自定义按钮吗?
我想用python GTK制作一个类似于设置菜单或控制面板的程序。我知道PyGTK有取消、退出和ok等库存按钮;但我无法更改这些按钮的标签或图标

您可以在屏幕上放置一个按钮,并在其中放置任何图像

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
#  test_icon.py
#  
#  Copyright 2015 John Coppens <john@jcoppens.com>
#  
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#  
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#  
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.
#  

import pygtk
import gtk

IMAGE_FILE = "/put/an/imagename here"

class MainWindow(gtk.Window):
    def __init__(self, debug = None):
        gtk.Window.__init__(self)
        self.connect("delete-event", self.on_delete_event)

        btn = gtk.Button()
        img = gtk.Image()
        img.set_from_file(IMAGE_FILE)
        btn.set_image(img)

        self.add(btn)
        self.show_all()

    def on_delete_event(self, win, data):
        gtk.main_quit()

    def run(self):
        gtk.mainloop()

def main():
    w = MainWindow()
    w.run()
    return 0

if __name__ == '__main__':
    main()
#/usr/bin/env python
#-*-编码:utf-8-*-
#
#test_icon.py
#  
#版权所有2015 John Coppens
#  
#这个程序是自由软件;您可以重新分发和/或修改它
#它是根据GNU通用公共许可证的条款发布的
自由软件基金会;许可证的第2版,或
#(由您选择)任何更高版本。
#  
#这个节目的发布是希望它会有用,
#但无任何保证;甚至没有任何关于
#适销性或适合某一特定目的。见
#有关更多详细信息,请参阅GNU通用公共许可证。
#  
#您应该已经收到GNU通用公共许可证的副本
#与此同时,;如果没有,请写信给自由软件
波士顿基金会51楼富兰克林街第五楼
#MA 02110-1301,美国。
#  
进口pygtk
进口gtk
IMAGE\u FILE=“/put/an/imagename在此”
类主窗口(gtk.Window):
def uuu init uuuu(self,debug=None):
gtk.Window.\uuuu初始化\uuuuu(自)
self.connect(“删除事件”,self.on_delete_事件)
btn=gtk.Button()
img=gtk.Image()
img.set_from_文件(图像_文件)
btn.设置图像(img)
自我添加(btn)
self.show_all()
删除事件中的def(自我、胜利、数据):
gtk.main_quit()
def运行(自):
gtk.mainloop()
def main():
w=主窗口()
w、 运行()
返回0
如果uuuu name uuuuuu='\uuuuuuu main\uuuuuuu':
main()
图像可以是多种格式,甚至SVG(矢量图形)、PNG等