Make Gtk errors and warnings show as message box


Usually, if there’s a warning or error in your application GTK with print out an error to the console.
I would like GTK to print the warning/error out as a message box (e.g. GtkMessageDialog). How can I do that?


I’d like to test my application before I release it. During this “testing phase” I’d like every error to pop up directly, so I can see it, since I won’t use and monitor the console during this phase.

As this does not seem to exist, I wrote a small python script showing all the errors:

import tkinter
from tkinter import *
from tkinter.messagebox import *
import sys
import os
from subprocess import *

def showHelp():
  print ("Usage:")
  print (" [program path] [program parameters]")

def run(args):

  # tkinter always needs a window for msg boxes. so we 
  # create one and then hide it.
  window = Tk()
  window.withdraw ()

  if (len (args) < 1):
    showHelp ()

  callArray = args
  handle = Popen(callArray, stdout=PIPE,stderr=PIPE)

  while (True):
    if (None != handle.poll()):

    #stdout = handle.stdout.readline()
    #if (stdout):
    #  tkinter.messagebox.showinfo (callArray[0], stdout)
    stderr = handle.stderr.readline()          
    if (stderr and not ("atk-bridge" in stderr)):
      tkinter.messagebox.showerror (callArray[0], stderr)

def main():
  args = sys.argv[1:]
  run (args)

if __name__ == "__main__":
  main ()

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.