Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to add a print dialog to my Python + GTK app, and I believe there are at least two methods:

  1. The upstream GTK print dialog
  2. The CUPS print dialog

I'm wondering which would be the recommended one to use for application development. I believe 2. is what Ubuntu uses, so I assume it will work well with indicators and with detecting system printers. However, I haven't been able to find any documentation at all for it.

Any recommendation on the best way to add a print dialog to my app?

share|improve this question
what do you mean by "ubuntu uses the CUPS dialog"? What part of Ubuntu? I think most (all) applications inherited from Gnome use the upstream GTK dialog. I would recommend you to do the same. – Timo Kluck Nov 21 '12 at 22:22
I simply said "I believe", as I'm not familiar with printing at all, so any advice, corrections or code snippets are welcome. I looked at… and I got the impression that there isn't a standard print dialog all apps use yet. – David Planella Nov 21 '12 at 22:51
Programming questions should be asked on stackoverflow. – psusi Nov 22 '12 at 0:58
@psusi: Programming in Ubuntu is a topic of AskUbuntu, please read the FAQ. – Javier Rivera Nov 22 '12 at 7:59
up vote 5 down vote accepted

It seems that a reasonable way to add printing to your app with Gtk would be the Gtk.PrintOperation. This is supposed to be the high-level, portable version of a print dialog.

In Python, a basic example could look like this:

from gi.repository import Gtk

class MyWindow(Gtk.Window):

    def __init__(self):
        Gtk.Window.__init__(self, title="Hello World Printing")
        self.button = Gtk.Button(label="Print A Rectangle")
        self.button.connect("clicked", self.on_button_clicked)

    def on_button_clicked(self, widget):
        pd = Gtk.PrintOperation()
        pd.connect("draw_page", self.draw_page)
        result =
            Gtk.PrintOperationAction.PRINT_DIALOG, None)
        print result  # handle errors etc.

    def draw_page(self, operation=None, context=None, page_nr=None):
        ctx = context.get_cairo_context()
        w = context.get_width()
        h = context.get_height()
        ctx.set_source_rgb(0.5, 0.5, 1)
        ctx.rectangle(w*0.1, h*0.1, w*0.8, h*0.8)

win = MyWindow()
win.connect("delete-event", Gtk.main_quit)
share|improve this answer
This is the correct way. It will try to run the native printdialog for the user's system. – Timo Nov 22 '12 at 12:23

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.