473,326 Members | 2,815 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

windows

hi!

i have two tkinter windows on top of each other. i would like it so that
the user has to complete the fields in the top windows before they can
interact with the window below it. that is, i dont want the user to close
the top window or minimize it or send it into the background.

how would i do it?

thanks

cheers


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
Jul 18 '05 #1
4 2045
Ajay wrote:
hi!

i have two tkinter windows on top of each other. i would like it so that
the user has to complete the fields in the top windows before they can
interact with the window below it. that is, i dont want the user to close
the top window or minimize it or send it into the background.


Look for grab, and what it does.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Ajay <ab******@mail.usyd.edu.au> wrote in message news:<ma**************************************@pyt hon.org>...
hi!

i have two tkinter windows on top of each other. i would like it so that
the user has to complete the fields in the top windows before they can
interact with the window below it. that is, i dont want the user to close
the top window or minimize it or send it into the background.

how would i do it?

thanks

cheers


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


There are documentations which say that Tkinter.Toplevel has
a methode .transient(root) which should make the Toplevel window
transient to its root window.
But I never managed to make it work.(W2K Python 2.2.2).
But here is a hackaround:

import Tkinter

#----------------------
def deiconify(widget):
#----------------------
widget.deiconify()
widget.grab_set()

#----------------------
def withdraw(widget):
#----------------------
widget.grab_release()
widget.withdraw()

# The root window
root=Tkinter.Tk()

# The Toplevel window
tl=Tkinter.Toplevel(root,width=400,height=200,bg=' white')

# Withdraw Toplevel, when destroyed
tl.protocol("WM_DELETE_WINDOW",lambda w=tl:withdraw(w))

# Make Toplevel not resizable
tl.resizable(width=False,height=False)

# Default state of Toplevel is withdrawn
tl.withdraw()

# Give Toplevel window a title
tl.title('Toplevel-Window')

# A Button on the root window to make Toplevel window visible
Tkinter.Button(root,text='Toplevel on',command=lambda w=tl:deiconify(w)).pack()

# Start mainloop
root.mainloop()

Regards
Peter
Jul 18 '05 #3
Ajay <ab******@mail.usyd.edu.au> wrote in message news:<ma**************************************@pyt hon.org>...
hi!

i have two tkinter windows on top of each other. i would like it so that
the user has to complete the fields in the top windows before they can
interact with the window below it. that is, i dont want the user to close
the top window or minimize it or send it into the background.

how would i do it?

thanks

cheers


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.


There are documentations which say that Tkinter.Toplevel has
a methode .transient(root) which should make the Toplevel window
transient to its root window.
But I never managed to make it work.(W2K Python 2.2.2).
But here is a hackaround:

import Tkinter

#----------------------
def deiconify(widget):
#----------------------
widget.deiconify()
widget.grab_set()

#----------------------
def withdraw(widget):
#----------------------
widget.grab_release()
widget.withdraw()

# The root window
root=Tkinter.Tk()

# The Toplevel window
tl=Tkinter.Toplevel(root,width=400,height=200,bg=' white')

# Withdraw Toplevel, when destroyed
tl.protocol("WM_DELETE_WINDOW",lambda w=tl:withdraw(w))

# Make Toplevel not resizable
tl.resizable(width=False,height=False)

# Default state of Toplevel is withdrawn
tl.withdraw()

# Give Toplevel window a title
tl.title('Toplevel-Window')

# A Button on the root window to make Toplevel window visible
Tkinter.Button(root,text='Toplevel on',command=lambda w=tl:deiconify(w)).pack()

# Start mainloop
root.mainloop()

Regards
Peter
Jul 18 '05 #4
Peter Abel wrote:
Ajay <ab******@mail.usyd.edu.au> wrote in message news:<ma**************************************@pyt hon.org>...
hi!

i have two tkinter windows on top of each other. i would like it so that
the user has to complete the fields in the top windows before they can
interact with the window below it. that is, i dont want the user to close
the top window or minimize it or send it into the background.

how would i do it?

thanks

cheers


----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.

There are documentations which say that Tkinter.Toplevel has
a methode .transient(root) which should make the Toplevel window
transient to its root window.
But I never managed to make it work.(W2K Python 2.2.2).


Read tk commands manual:

"""
wm transient window ?master?
If master is specified, then the window manager is informed that window is
a transient window (e.g. pull-down menu) working on behalf of master (where
master is the path name for a top-level window). Some window managers will use
this information to manage window specially.
"""

Nothing is said about which window should have the grab. And in fact, Windows
actually does something when a window is made transient; try this in an
interactive Python session:
from Tkinter import *
root = Tk()
wdw = Toplevel()
wdw.transient(root)


You can first notice that the minimize and maximize buttons have disappeared
from the secondary window's title bar, and that the close button has shrinked a
little. Then, if you try to put the main window above the secondary one, you'll
see that you can't. But you can still make the main window active.

So transient is only part of the solution. You also want to set the grab on the
secondary window, and then wait for the secondary window to close. Here is an
example doing that:

--modal.py-------------------------------------------------
from Tkinter import *

root = Tk()

def go():
wdw = Toplevel()
Entry(wdw).pack()
wdw.transient(root)
wdw.grab_set()
root.wait_window(wdw)
print 'done!'

Button(root, text='Go', command=go).pack()
Button(root, text='Quit', command=root.quit).pack()

root.mainloop()
-----------------------------------------------------------

So this is the magical sequence to make a window modal in Tkinter: transient,
grab_set, wait_window.

[snip]

HTH
--
- Eric Brunel <eric (underscore) brunel (at) despammed (dot) com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Ken Lindner | last post by:
I have a need to become familiar with SQL Server 2000 for work. Needless to say I am new to SQL Server any version, but not IT in general. My employer has provided me with the SQL Server 2000...
7
by: lvpaul | last post by:
Hallo ! I am using IIS-Windows-Authentication in my intranet (web.config <authentication mode="Windows" /> <identity impersonate="true" /> How can I get the users (client) IP-Address ? I...
7
by: Tyler Foreman | last post by:
Hello, I have a strange problem that occurs every so often in my application. It usually takes place when I hide one form and activate another. What happens is I get the following exception:...
1
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. I'm having trouble getting the code that I've written to work, can anyone shed some light as to where I'm...
0
by: Scott Davies | last post by:
Hi, I'm looking for some help on a small program that I'm trying to develop in VB.NET. The program I'm trying to develop needs to be able to do the following: - Select remote server -...
4
by: Rod Gill | last post by:
Hi, I have a form that when opened in the designer appears of the screen. The form selector can't be dragged (or resized) and if I scroll right and down to centralise it the form simply jumps...
2
by: sambo251 | last post by:
After running a few updates I get this very annoying "Windows Installer" error #1706 that will ne go away! It keeps saying that it cannot find the file "instantsharedevices.msi", that it is on...
1
by: mfunkmann | last post by:
Hi, I recently got an error and I don't know how to fix it: Error 1 'System.Data.DataColumn' does not contain a definition for 'Windows' C:\c#\CsharpPRO\Form1.Designer.cs 304 77 CsharpPRO I...
0
AmberJain
by: AmberJain | last post by:
Windows Autorun FAQs: List of autostart locations Linked from the Original article- "Windows Autorun FAQs: Description". Que: Can you list all the autostart locations for windows? Ans: Here is...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.