A minimal GTK+ Application: a window with a title. |
Use if you need support. |
from gi.repository import Gtk
import sys
class MyApplication(Gtk.Application):
def do_activate(self):
# create a Gtk Window belonging to the application itself
window = Gtk.Window(application=self)
# set the title
window.set_title("Welcome to GNOME")
# show the window
window.show_all()
# create and run the application, exit with the value returned by
# running the program
app = MyApplication()
exit_status = app.run(sys.argv)
sys.exit(exit_status)
set_default_size(200, 100)
définit la taille par défaut de la fenêtre à une largeur de 200
et une hauteur de 100
; si, au lieu d'un nombre positif, vous lui transmettez -1
, vous obtenez la taille par défaut.
set_position(Gtk.WindowPosition.CENTER)
place la fenêtre au centre de l'écran. Les autres options possibles sont : Gtk.WindowPosition.NONE, Gtk.WindowPosition.MOUSE, Gtk.WindowPosition.CENTER_ALWAYS, Gtk.WindowPosition.CENTER_ON_PARENT
.
Dans cet exemple, les éléments suivants sont utilisés :
GtkApplication
GtkWindow