Python Forum
GTK main window calling a main window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
GTK main window calling a main window
I've been googling all day and can't find how to do this. 

I have my main Python 3 Gtk+3 window.  I want to create a overlay window (smaller than the main) that is centered on the main window.  The overlay window will have focus - users cannot select the main window until the overlay is closed.  The overlay window will consist of a grid container(uses entire overlay window).  I will open and close the overlay as needed.

Can anyone point me in the right direction to do this?  I tried a dialog but couldn't get it to accept a grid (box only?).
I have been able to insert a grid into the box on a dialog. However I cannot get it to restrict the size (window is the full width of the main window) or control its location (always on bottom).
(Oct-13-2016, 09:40 PM)DennisT Wrote: I have been able to insert a grid into the box on a dialog.  However I cannot get it to restrict the size (window is the full width of the main window) or control its location (always on bottom).

it is always best to post the code you have so far. It makes it easier to offer suggestions based on what you have.
Please read the Help section on how to post code.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
OK, I'm trying to get dialogs to work the way I want.  I have a 800x600 main window.  I want to create a 400x200 dialog window in the center of the main window.  I need to transfer data from the dialog back to the main window.  I've been able to do this using a global.  However I cannot fix the size of the dialog and center it in the main window.  It appears at the bottom of the main window and covers the entire width.
  Code is running on a RPi3 Raspbian w.matchbox window manager.

# Import functions
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GObject
PINFO = ''
class TestPopup(Gtk.Dialog):
    def __init__(self, main_window):
        global PINFO
        Gtk.Dialog.__init__(self, "Popup", main_window, 0, ("Exit", Gtk.ResponseType.OK))       #create dialog window + exit button
        self.set_default_size(400, 200)                                                        #control size
        self.set_size_request(400, 200)                                                        #control size
#        self.set_decorated(0)
#        self.set_resizable(False)
        geom = Gdk.Geometry()
        geom.min_width = 400
        geom.max_width = 400
        geom.min_height = 200
        geom.max_height = 200
        geom.base_width = 400
        geom.base_height = 200
        hints = Gdk.WindowHints.MIN_SIZE | Gdk.WindowHints.MAX_SIZE | Gdk.WindowHints.BASE_SIZE
        self.set_geometry_hints(None, geom, hints)
        W,H = self.get_size()
        print ('Dialog width='+str(W)+'  height='+str(H))
        box = self.get_content_area()                                   #set dialog's container

        self.Titletext = Gtk.Label()                             #Fixed title
        self.Titletext.set_text("Test Popup")        #title

        PINFO = 'TestPopup complete'

class MWin(Gtk.Window):
    def __init__(self):
        global PINFO
        PINFO = ''

        self.set_default_size(800,600) #set window size

        fixed = Gtk.Fixed()                                         #add fixed container to window
        self.ExitButton = Gtk.Button(label=" Exit ")              #add reset button
        fixed.put(self.ExitButton,10,600-100)       #set ResetButton location
        self.ExitButton.connect("clicked", self.exit_button_clicked) #set ResetButton click action

        self.DiagButton = Gtk.Button(label=" Dialog ")             #add button
        fixed.put(self.DiagButton,180,600-100)       #set Button location
        self.DiagButton.connect("clicked", self.ButtonClicked) #set EmpInfo Button click action

    def exit_button_clicked(self, widget):                         #when ResetButton is clicked
        exit()                                                      #we exit.  kiosk env will auto start new session

    def ButtonClicked (self, widget):
        W,H = self.get_size()
        print ('mainwin width='+str(W)+'  height='+str(H))
        print ('PINFO start:'+PINFO)
        dialog = TestPopup(self)                                  #display error window
        response =
        print ('PINFO return:'+PINFO)
        return True

MainWin = MWin()
#cursor =    #change mouse pointer to blank (transparent)
#MainWin.get_window().set_cursor(cursor)                 #and set it
As you can see, there's a bunch of redundant code I've played with trying to get the dialog to the size and location I want.  Interestingly. self.get_size does return the size I want.  It just doesn't display that size.
I suspect this issue is with matchbox. I've been able to work around the dialog issue. Using a fixed container on my main window I can control size/location. Had to use a GObject.timeout to help emulate the focus being held to the pseudo dialog. Messy, ugly, but workable. Sure would have been a lot easier if Dialog worked as I wanted. :(

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] [split] [split] How to make a window stay on top knoxvilles_joker 10 2,165 May-22-2021, 03:54 AM
Last Post: knoxvilles_joker
  [PyQt] My WIndow isnt opening at all. SovietMilkerGenerak 1 783 Apr-24-2021, 12:25 PM
Last Post: Yoriz
  [PyQt] How to clip layout to sides and bottom of main window? Valmont 9 741 Mar-24-2021, 10:00 PM
Last Post: deanhystad
  [Tkinter] mpv window freeze before video end rfeyer 7 645 Feb-20-2021, 09:34 PM
Last Post: rfeyer
  Subprocess window won't open on Mac blakefindlay 1 698 Feb-06-2021, 04:23 AM
Last Post: deanhystad
  [Kivy] Kivy pop up shows duplicate buttons from main screen CEKinch 0 596 Feb-05-2021, 05:40 PM
Last Post: CEKinch
  "tkinter.TclError: NULL main window" Rama02 1 896 Feb-04-2021, 06:45 PM
Last Post: deanhystad
  [PyQt] Opening new window ifigazsi 2 498 Jan-20-2021, 04:16 PM
Last Post: ifigazsi
Question closing a "nested" window with a button in PySimpleGUI and repeating this process Robby_PY 9 2,094 Jan-18-2021, 10:21 PM
Last Post: Serafim
  Trying to make random image loop in Tk window using python Jediguy18 1 587 Dec-30-2020, 04:56 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020