我的应用程序中有一个按钮,我希望它的尺寸为 23x23 像素,库存图标为 16x16 像素。
我想出了:
closeButton = gtk.ToolButton(gtk.STOCK_CLOSE)
closeButton.set_size_request(23, 23)
但此代码仅更改按钮的大小而不更改图标的大小:/
如何在我的按钮上缩放股票图标?是否有任何小版本的库存商品?像 gtk.STOCK_SMALL_CLOSE 之类的东西?
编辑这是测试创建小库存项目的可能性的示例程序
import gtk
class Tab(gtk.VBox):
def __init__(self, caption):
gtk.VBox.__init__(self)
self.Label = self.__createLabel(caption)
self.show_all()
def __createLabel(self, caption):
hbox = gtk.HBox()
label = gtk.Label(caption)
hbox.pack_start(label, True, True)
closeButton = gtk.ToolButton(self._getCloseIcon())
hbox.pack_start(closeButton, False, False)
hbox.show_all()
return hbox
def _getCloseIcon(self):
raise NotImplementedError
class TabWithNormalIcons(Tab):
def __init__(self, caption):
Tab.__init__(self, caption)
def _getCloseIcon(self):
return gtk.STOCK_CLOSE
class TabWithImage16Icons(Tab):
def __init__(self, caption):
Tab.__init__(self, caption)
def _getCloseIcon(self):
return gtk.image_new_from_stock(gtk.STOCK_CLOSE, 16)
class TabWithSmallToolbarIcons(Tab):
def __init__(self, caption):
Tab.__init__(self, caption)
def _getCloseIcon(self):
return gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_SMALL_TOOLBAR)
class TabWithMenuIcons(Tab):
def __init__(self, caption):
Tab.__init__(self, caption)
def _getCloseIcon(self):
return gtk.image_new_from_stock(gtk.STOCK_CLOSE, gtk.ICON_SIZE_MENU)
class App(gtk.Window):
def __init__(self):
gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
self.connect('destroy', lambda event: gtk.main_quit())
self.set_default_size(640, 480)
notebook = gtk.Notebook()
tabNumber = 1
#Icon normal sizes
for i in range(3):
tab = TabWithNormalIcons('Tab %s' % str(tabNumber))
notebook.append_page(tab, tab.Label)
tabNumber += 1
#Icons with 16 pixel Image
for i in range(3):
tab = TabWithImage16Icons('Tab %s' % str(tabNumber))
notebook.append_page(tab, tab.Label)
tabNumber += 1
#Icons with small toolbar images
for i in range(3):
tab = TabWithSmallToolbarIcons('Tab %s' % str(tabNumber))
notebook.append_page(tab, tab.Label)
tabNumber += 1
#Icons with menu images
for i in range(3):
tab = TabWithMenuIcons('Tab %s' % str(tabNumber))
notebook.append_page(tab, tab.Label)
tabNumber += 1
self.add(notebook)
self.show_all()
a = App()
gtk.main()