473,574 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter, tkMessagebox and overrideredirec t

Hi everybody.

I have this code snippet that shows a window without a titlebar (using
overrideredirec t) and two buttons on it: one quits and the other one
brings up a simple tkMessageBox.
On Windows (any flavour) the tkMessagebox brings up over the
underlying window.
On Linux (apparently any flavour) the tkMessagebox brings up under the
underlying window.
You can drag the popup window near the main window to discover if it's
over or under it.
Obviously I would like to show a popup that is over the main window!
Before asking I tried, I read, I googled, I pulled my hair off, but no
avail...
Any hints?
Thanks a lot for your time.
Ciao.
Marco.

import tkMessageBox
from Tkinter import *

class App():
def __init__(self):
self.root = Tk()
self.root.overr ideredirect(1)
self.frame = Frame(self.root , width=320, height=200,
borderwidth=5, relief=RAISED)
self.frame.pack _propagate(Fals e)
self.frame.pack ()
self.bQuit = Button(self.fra me, text="Quit",
command=self.ro ot.quit)
self.bQuit.pack (pady=20)
self.bHello = Button(self.fra me, text="Hello",
command=self.he llo)
self.bHello.pac k(pady=20)

def hello(self):
tkMessageBox.sh owinfo("Popup", "Hello!")

app = App()
app.root.mainlo op()

Jun 5 '07 #1
6 13893
On Tue, 05 Jun 2007 18:18:51 +0200, <ma*******@gmai l.comwrote:
Hi everybody.

I have this code snippet that shows a window without a titlebar (using
overrideredirec t) and two buttons on it: one quits and the other one
brings up a simple tkMessageBox.
On Windows (any flavour) the tkMessagebox brings up over the
underlying window.
On Linux (apparently any flavour) the tkMessagebox brings up under the
underlying window.
You can drag the popup window near the main window to discover if it's
over or under it.
Obviously I would like to show a popup that is over the main window!
Before asking I tried, I read, I googled, I pulled my hair off, but no
avail...
Any hints?
Apparently:

def hello(self):
self.root.after _idle(self.root .lower)
tkMessageBox.sh owinfo("Popup", "Hello!")

does something looking like what you want. I don't know of any way to get
the identifier for the window created by tkMessageBox.sh owinfo, so if
there's a way to do better than that, I don't know it.

As an aside, having a window with overrideredirec t(1) creating "normal"
windows such as the one created via tkMessageBox.sh owinfo is asking for
problems. What are you trying to do here?

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Jun 6 '07 #2
On Jun 6, 8:55 am, "Eric Brunel" <see.signat...@ no.spamwrote:
Apparently:
Eric,
first of all, thanks!
def hello(self):
self.root.after _idle(self.root .lower)
tkMessageBox.sh owinfo("Popup", "Hello!")
Well, this lowers the background frame but I want to keep it visible
under the popup.
As an aside, having a window with overrideredirec t(1) creating "normal"
windows such as the one created via tkMessageBox.sh owinfo is asking for
problems. What are you trying to do here?
I just need a window without the titlebar as my main window (think of
it as a kiosk application). No titlebar is mandatory :-(
I place controls on it and I open popup dialog windows.
If there is a better way to do it, I would be happy to know it.
Thanks again.
Ciao.
Marcio.

Jun 6 '07 #3
On Wed, 06 Jun 2007 14:26:12 +0200, <ma*******@gmai l.comwrote:
>As an aside, having a window with overrideredirec t(1) creating "normal"
windows such as the one created via tkMessageBox.sh owinfo is asking for
problems. What are you trying to do here?

I just need a window without the titlebar as my main window (think of
it as a kiosk application). No titlebar is mandatory :-(
I place controls on it and I open popup dialog windows.
If there is a better way to do it, I would be happy to know it.
My only advice would then be to avoid using the standard functions to
create dialog boxes, and to create them yourself. For example:
----------------------------------------------------------
from Tkinter import *

class App:
def __init__(self):
self.root = Tk()
self.root.overr ideredirect(1)
frm = Frame(self.root , width=320, height=200, borderwidth=5,
relief=RAISED)
frm.pack_propag ate(0)
frm.pack()
Button(frm, text="Quit", command=self.ro ot.quit).pack(p ady=20)
Button(frm, text="Hello", command=self.he llo).pack(pady= 20)

def hello(self):
dialogWdw = Toplevel()
dialogWdw.title ('Popup')
Label(dialogWdw , text='Hello!'). pack(side=TOP)
Button(dialogWd w, text='OK',
command=dialogW dw.destroy).pac k(side=TOP)
dialogWdw.tkrai se(self.root)
self.root.wait_ window(dialogWd w)

app = App()
app.root.mainlo op()
----------------------------------------------------------

But even with this, you may run into problems. For example, on my Linux
box with my window manager, the main window goes behind all other windows
once the button in the dialog is clicked. So I'd say that if you want to
bypass the window manager, bypass it for everything and do
overrideredirec t(1) on all the windows you create. But this means that
you'll have to do everything "manually", especially window stacking.
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Jun 6 '07 #4
On Jun 6, 3:38 pm, "Eric Brunel" <see.signat...@ no.spamwrote:
My only advice would then be to avoid using the standard functions to
create dialog boxes, and to create them yourself. For example:
----------------------------------------------------------
from Tkinter import *
[snip]
app.root.mainlo op()
----------------------------------------------------------
But even with this, you may run into problems. For example, on my Linux
box with my window manager, the main window goes behind all other windows
once the button in the dialog is clicked. So I'd say that if you want to
bypass the window manager, bypass it for everything and do
overrideredirec t(1) on all the windows you create. But this means that
you'll have to do everything "manually", especially window stacking.
Besides that, the popup window is yet under the main frame... :-(
Seems to me that dialogWdw.tkrai se(self.root) doesn't do its job.
It's like overrideredirec t in main window override also tkraise on it.

I can't believe there isn't an easier way to make a kiosk application
without titlebar.
Perhaps to create a normal window bigger than screen with title bar
outside it?
And after how can I ignore titlebar menu command or "x" and "-"
button?
Or is it possible to create a main Toplevel without "x" and "-"?

Thanks.
Ciao.
Marco.
Jun 7 '07 #5
On Thu, 07 Jun 2007 09:04:24 +0200, <ma*******@gmai l.comwrote:
[snip]
I can't believe there isn't an easier way to make a kiosk application
without titlebar.
That's not the problem: there *is* an easy way, and you found it:
overrideredirec t(1). But now you're trying to mix windows ignored by the
window manager - as you've told it to - and windows that *are* managed by
the window manager. This is where the problem is.
Perhaps to create a normal window bigger than screen with title bar
outside it?
This won't work on some platforms and/or with some window managers... And
there's no portable way to do that, as sometimes, the dimensions you give
for the window includes the window decorations, and sometimes they don't..
And after how can I ignore titlebar menu command or "x" and "-"
button?
For the 'X' button, it's quite simple:
myToplevel.prot ocol('WM_DELETE _WINDOW', lambda: None)

For the '-' button, I don't know any way.
Or is it possible to create a main Toplevel without "x" and "-"?
Apart from overrideredirec t(1), I don't think there's any.
BTW, what are you trying to do here? Will your application run on a
"normal" desktop computer? Or will it run on special devices such as
vending machines or similar? If in the first case, my advice would be to
give up this design (which many people hate, BTW) and use normal windows..
You'll have far less trouble and will probably make your users happier. If
in the second case, you shouldn't rely on an existing window manager, and
try to design your GUI so that doing things "manually" will be easier. For
example, instead of displaying a dialog for a message, maybe you should
just reserve a screen zone to display the message, optionally displaying
it in a special color or making it blink so that the user can't miss it.
You may also consider using the "place" layout method to display things at
random coordinates in your application window. For example:

--------------------------------------------------------
from Tkinter import *

class App:
def __init__(self):
self.root = Tk()
self.root.overr ideredirect(1)
frm = Frame(self.root , width=320, height=200,
borderwidth=5, relief=RAISED)
frm.pack_propag ate(0)
frm.pack()
Button(frm, text="Quit", command=self.ro ot.quit).pack(p ady=20)
Button(frm, text="Hello", command=self.he llo).pack(pady= 20)

def hello(self):
self.dialogWdw = Frame(self.root , borderwidth=2, relief=RAISED)
Label(self.dial ogWdw, text='Hello!'). pack(side=TOP, padx=20,
pady=4)
Button(self.dia logWdw, text='OK',
command=self.de stroyDialog).pa ck(side=TOP, padx=20, pady=4)
self.dialogWdw. place(x=170, y=100, anchor='center' )

def destroyDialog(s elf):
self.dialogWdw. place_forget()
self.dialogWdw. destroy()
app = App()
app.root.mainlo op()
--------------------------------------------------------

HTH
--
python -c "print ''.join([chr(154 - ord(c)) for c in
'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"
Jun 7 '07 #6
On Jun 7, 12:01 pm, "Eric Brunel" <see.signat...@ no.spamwrote:
BTW, what are you trying to do here? Will your application run on a
"normal" desktop computer? Or will it run on special devices such as
vending machines or similar?
You got it: it's a special device.
in the second case, you shouldn't rely on an existing window manager, and
try to design your GUI so that doing things "manually" will be easier. For
example, instead of displaying a dialog for a message, maybe you should
just reserve a screen zone to display the message, optionally displaying
it in a special color or making it blink so that the user can't miss it.
You may also consider using the "place" layout method to display things at
random coordinates in your application window. For example:
You are right and I think it's not a big deal for simple popup
messages.
But when I need tkFileDialog.as kdirectory I think things get harder.
I would prefer not have to reimplement the whole stuff from scratch...

Ciao.
Marco.
P.S. BTW I already owe you a pizza for your help. Do you think you can
be at http://www.pycon.it this weekend? :-)

Jun 7 '07 #7

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

Similar topics

4
9897
by: Yann.K | last post by:
Hello. Using Tkinter, i would create a widget which display a shell command return. This return is long, and i would display a real time display (like with the tail -f commande on Linux) I think to use the text widget. I have no problem to execute the command, but how to display, in a *real-time* fashion the shell retrun?
1
2262
by: Club-B42 | last post by:
when i start opt_newlogin.py directly it works fine(outputs '1 1 1 1'), but if i start it from options.py there is an error(outputs ''). ======== opt_newlogin.py ======== from config import * from Tkinter import * from opt_newlogin import newlogin
5
2993
by: max(01)* | last post by:
hello. i wrote a very simple tkinter demo program that uses menus, buttons, labels, entries, frames and secondary toplevels. it is a python version of a java program made by a colleague. the user can create ("Scrivi") a record with his second name, first name and date of birth, save ("Salva") the record to a file or read in ("Leggi") a...
3
27386
by: Glen | last post by:
Is it possible to to detect a Tkinter top-level window being closed with the close icon/button (top right), for example to call a function before the window actually closes? Python 2.4 / Linux (2.6 kernel) if that makes any difference. Any info would be greatly appreciated. Thanks Glen
0
2343
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they...
2
6269
by: Nick Craig-Wood | last post by:
I'm just starting out with Tkinter programming (using Programming Python as a reference), and I couldn't find the answer to this anywhere... How do you catch general exceptions in a Tkinter program. If you run the below and click the "Exception" or "Callback Exception" buttons you see a traceback on stderr under unix, and nothing at all...
4
3183
by: jmdeschamps | last post by:
why is the button sunken when called through a bind method, and not with the command attribute? Thank you! ## Cut'nPaste example from Tkinter import * import tkMessageBox class Vue(object):
0
1379
by: dudeja.rajat | last post by:
Hi, I'm working on Windows Platform I'm facing some problem with the tkMessageBox. My code is as below: import tkMessageBox import Tix from Tkinter import * if len(installedLibPath) != len(listOfLibraries):
0
1754
by: Guilherme Polo | last post by:
On Thu, Aug 28, 2008 at 10:29 AM, <dudeja.rajat@gmail.comwrote: It is good to post a short code sample that demonstrates the problem, but it has to run by itself at least. tkMessageBox blocks till you finish it, maybe that is what is causing your problem but it is hard to tell what you are doing wrong in that myAppGui without seeing it...
0
7832
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8093
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8262
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
8129
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5643
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5331
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3768
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3785
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1094
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.