python de Gtk+3 #13
はじめに
前に予告したメッセージダイアログを紹介しようと思います。
本題
まず例を見てください。
#!/usr/bin/env python # -*- coding:utf-8 -*- from gi.repository import Gtk class MainWindow(Gtk.Window): def __init__(self): Gtk.Window.__init__(self, title=u'MessageDialog') button = Gtk.Button(u'Click Here') button.connect('clicked', self.on_button_clicked) self.add(button) self.connect('delete-event', Gtk.main_quit) self.show_all() def on_button_clicked(self, widget): dialog = Gtk.MessageDialog(self, 0, Gtk.MessageType.ERROR, Gtk.ButtonsType.CANCEL, u'ERROR') dialog.format_secondary_text(u'This is an ERROR MessageDialog') print u'ERROR' dialog.run() dialog.destroy() if __name__ == '__main__': MainWindow() Gtk.main()
こんなかんじです。
エラーメッセージ以外でも
- インフォメーション
- 注意
などもできます。
おわりに
今回はPEP8を意識して書きましたw
class MainWindow(Gtk.Window):
の前の空白が2行じゃないとダメなんですね。
まだまだ勉強中です。
他にもなにか教えていただけることがあればコメントまでww