3

I'm trying to use a custom icon in the titlebar (and taskbar if possible) of a GUI made in Traits UI, however I cannot find any information on how to do so. There is an icon attribute in the Traits UI View class, but I can't get it to change anything: http://docs.enthought.com/traitsui/traitsui_user_manual/custom_view.html#index-15

Google suggests there may be a convoluted solution involving directly interacting with pyqt4 but I wanted to check there wasn't a simpler solution first.

The gui is intended to run on Linux and Windows.

shad0w_wa1k3r
  • 12,955
  • 8
  • 67
  • 90
Siyh
  • 1,747
  • 1
  • 17
  • 24

1 Answers1

3

The solution was to use the pyface ImageResource class. See:

from traits.api import HasTraits, Str
from traitsui.api import View, Item
from pyface.image_resource import ImageResource

class Person(HasTraits):
    first_name = Str
    last_name = Str

    view = View(Item('first_name'),
             Item('last_name'),
             icon=ImageResource('image_path.png'))

Person().configure_traits()
Siyh
  • 1,747
  • 1
  • 17
  • 24
  • 1 more detail: the file is expected to be (and searched for) inside a folder called "images/" located next to the module containing the view code. – jonathanrocher Jan 17 '18 at 19:21