is there a possiblity to change the position of a Gtk.Dialog?
At the moment it's poppin up right in the center of my main-Window. Can I set values, so it's more to the left or right?
Thank you!
Here's a minimal example of how you might want to move a Gtk.Dialog to your desired position:
import gi
gi.require_version("Gtk", "3.0")
from gi.repository import Gtk
class DialogExample(Gtk.Dialog):
def __init__(self, parent, x, y):
Gtk.Dialog.__init__(self, title="My Dialog", transient_for=parent, flags=0)
self.set_default_size(150, 50)
# Get current position of dialog
pos = self.get_position()
# Move dialog to the desired location
self.move(pos[0] + x, pos[1] + y)
label = Gtk.Label(label="This is a dialog to display additional information")
box = self.get_content_area()
box.add(label)
self.show_all()
class DialogWindow(Gtk.Window):
def __init__(self):
Gtk.Window.__init__(self, title="Dialog Example")
self.set_border_width(6)
button = Gtk.Button(label="Open dialog")
button.connect("clicked", self.on_button_clicked)
self.add(button)
def on_button_clicked(self, widget):
# Open dialog 200 px to the left relative to main window
dialog = DialogExample(self, -200, 0)
dialog.run()
dialog.destroy()
win = DialogWindow()
win.connect("destroy", Gtk.main_quit)
win.show_all()
Gtk.main()
Sources: