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
#4
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.

#!/usr/bin/python3
# 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_border_width(9)
#        self.set_decorated(0)
#        self.set_resizable(False)
        self.resize(400,200)
        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)
        self.resize(400,200)
        W,H = self.get_size()
        self.set_gravity(Gdk.Gravity.CENTER)
        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
        box.add(self.Titletext)

        PINFO = 'TestPopup complete'
        return

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

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

        fixed = Gtk.Fixed()                                         #add fixed container to window
        self.add(fixed)
        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 = dialog.run()
        dialog.destroy()
        self.show_all()
        print ('PINFO return:'+PINFO)
        return True

#---------------------------------------------------------------------------------------
MainWin = MWin()
MainWin.show_all()
#cursor = Gdk.Cursor.new(Gdk.CursorType.BLANK_CURSOR)    #change mouse pointer to blank (transparent)
#MainWin.get_window().set_cursor(cursor)                 #and set it
Gtk.main()
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.
Reply


Messages In This Thread
GTK main window calling a main window - by DennisT - Oct-13-2016, 06:25 PM
RE: GTK main window calling a main window - by DennisT - Oct-18-2016, 06:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyqt5 - Close a modal window Ninja2112 9 1,000 Apr-23-2025, 02:56 PM
Last Post: deanhystad
  Transparent window background, but not text on it muzicman0 8 7,761 Feb-13-2025, 06:16 AM
Last Post: elonnmusk
  [PyQt] Popup window not coming RamanSMann 2 928 Jan-02-2025, 02:18 AM
Last Post: lyly19
  [Kivy] Asynchronous operation without window freezing T800 0 786 Dec-06-2024, 05:40 AM
Last Post: T800
  [Tkinter] Modal window DPaul 16 9,960 Nov-05-2024, 04:18 PM
Last Post: kaliumster
  Tkinter multiple windows in the same window hosierycouch 1 1,341 May-30-2024, 04:28 AM
Last Post: deanhystad
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 2,812 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [Tkinter] CTkScrollableDropdown error: bad window path name ".!ctkscrollabledropdown" CopperGenie 1 1,832 Mar-03-2024, 04:32 AM
Last Post: deanhystad
  [Tkinter] (CLOSED) CTkScrollableDropdown error: bad window path name ".!ctkscrollabledropdown" CopperGenie 4 2,752 Mar-03-2024, 03:21 AM
Last Post: CopperGenie
  [PyQt] main GUI is not shown flash77 3 1,849 Feb-20-2024, 05:27 PM
Last Post: flash77

Forum Jump:

User Panel Messages

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