How do I prevent master window from being accessed with child window present?

M

Marc

Hi,

I am doing a gui application where child windows pop up with options
after the user selects particular buttons from the master window.
However, the master window is still active underneath the child
window. If they accidentally press the same button again they can get
the same copy of two child windows, and that screws up a bunch of the
database stuff that I am trying to collect.

I have tried using the 'transient' method, and that prevents the
master window from being highlighted. But the user can still push
buttons on the master window if the child window is moved aside.

How do I disable the master window until the child window is closed?

Thanks,
Marc
 
C

Cliff Wells

Hi,

I am doing a gui application where child windows pop up with options
after the user selects particular buttons from the master window.
However, the master window is still active underneath the child
window. If they accidentally press the same button again they can get
the same copy of two child windows, and that screws up a bunch of the
database stuff that I am trying to collect.

I have tried using the 'transient' method, and that prevents the
master window from being highlighted. But the user can still push
buttons on the master window if the child window is moved aside.

How do I disable the master window until the child window is closed?

And which GUI toolkit are you using? Most have an option to open a
window as "modal" (although this might be limited to dialogs for your
particular toolkit) which means it retains the focus exclusively until
it's dismissed.
 
M

Michael Peuser

Marc said:
I guess knowing which kit would help. I am using Tkinter.
Of course you were usind Tkinter...

(1) You can use the modal approach (have a look how Pmw are doing this.
(2) Disable all your controls in the main widget when you show the child
window.
(3) "withdraw" the main window (this is not iconify!)

Example:
from Tkinter import *

m=Tk()
m.title("Parent")
c=Toplevel(m)
c.title("Child")
Button(c,text="Hello",command=c.destroy).pack()

c.bind("<Destroy>",lambda x:m.deiconify())
# note we need lambda to get rid of the Destroy argument
#we should "bind", because there are many ways a window can be killed

m.withdraw()

mainloop()
 
E

Eric Brunel

Marc said:
Hi,

I am doing a gui application where child windows pop up with options
after the user selects particular buttons from the master window.
However, the master window is still active underneath the child
window. If they accidentally press the same button again they can get
the same copy of two child windows, and that screws up a bunch of the
database stuff that I am trying to collect.

I have tried using the 'transient' method, and that prevents the
master window from being highlighted. But the user can still push
buttons on the master window if the child window is moved aside.

How do I disable the master window until the child window is closed?

childWindow.grab_set()

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top