5

I'm developing a python/tkinter application, and finding the default messagebox lacked flexibility, I programmed my own using Toplevel. I was rather successful in recreating the messabox appearance, however, I could not find a way to obtain the icons displayed in normal tkinter messagebox (i.e. : error, warning, info icons...)

I did some research didn't find much, except that those image were stored in a win32 DLL file... Also tried looking into the tkinter messagebox module code, but its only an interface transferring from python to TCL code I can't find (and probably wouldn't be able to read anyway...)

Is there anyway to get files or rough equivalents (PhotoImage objects) for these icons using either python or TCL executed though Tk().tk.call()? Or any other (thourghly explained then) way to achieve this?

Right now the best solution I can think of is to use screencapture, and save the icons to files, but I'd rather be able to access the original ones...

Thanks in advance !

dlesbre
  • 357
  • 3
  • 9

1 Answers1

5

The rough equivalents are available as (tk global variables):

::tk::icons::warning
::tk::icons::error
::tk::icons::information
::tk::icons::question

Like anything that is not documented, it is subject to change in the future, but these should be stable.

Brad Lanam
  • 5,192
  • 2
  • 19
  • 29
  • Thanks! After a bit of fidling around, I found two ways to access such images: the first is using `Label(root, image = "::tk::icons::error")` and similar, it gives me a colored images, but it's slightly different from the messagebox icons (the error icon is a no-entry sign and not a cross for instance), the second uses `Label(root, bitmap = "error")` and similar, which gives me a black bitmap icon, also different (error sign looks here like a no-parking sign...) The ones I get through the first method are okay, but I'm wondering why they're different, and if I can get the messagebox ones? – dlesbre Jun 17 '16 at 08:51
  • On Windows or Mac OS X, you get the native implementation of the message box, and the native images for that platform. These images are the ones used on Linux. You can try [twapi](http://twapi.sourceforge.net/v4.0/resource.html), but I don't know where those resources are stored in windows, nor how to use twapi from python. – Brad Lanam Jun 17 '16 at 12:59
  • Here are the windows messagebox icon names: [windows messagebox](https://msdn.microsoft.com/en-us/library/windows/desktop/ms645505(v=vs.85).aspx) – Brad Lanam Jun 17 '16 at 13:36
  • I wonder if after five years you might have an update to this answer? – WinEunuuchs2Unix May 23 '21 at 21:41