Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Tkinter messagebox
#1
Hi Guys,

I'm using the tkinter message box which works fine but I'm struggling to get code that checks if a messagebox is already open. So my working code is below but when the script is run again I need to ask if there is already a messagebox open.
def show_window(message):

 # hide main window
    window = Tk()
    window.eval('tk::PlaceWindow %s center' % window.winfo_toplevel())
    window.withdraw()

    # message box display
    window.wm_attributes("-topmost", 1)
    messagebox.showinfo("Information", message)
    window.deiconify()
    window.destroy()
    window.quit()
Reply
#2
There is no way for you to get information about the message box window. In all but the strangest use cases you know that the message window was closed because your program can do things. When the message window is visible, events are locked out so you cannot push buttons or type or interact with controls in any way. If a control's command is called you know the message window was closed. The function that drew the message window is frozen, waiting for the window to close. If code in your command function is executing you know the message window was closed.

If you want a message window like thing that can remain open, you'll need to write that yourself. Just make a toplevel window that can display a message.

The code you posted is very strange. What is it supposed to accomplish?
Reply
#3
This is a simple messagebox:
import tkinter as tk

from tkinter import messagebox

win = tk.Tk()
win.geometry("100x200")
win.withdraw()

messagebox.showinfo("Info Box", "Your info here")
win.mainloop()
Reply
#4
win.mainloop() may not be necessary. In Linux, the program is then not terminated properly.
It also works without win.mainloop()
Reply
#5
Thanks for all your replies.
I'm not a programmer so grabbed this code off the web ages ago - it works so I didn't change it - I wanted the window to be centre screen and top level i.e not under other windows so I thought some of the commands achieved this.
I'm running the python script from a C++ program using ShellExecuteW on a timer - if a particular file doesn't exist the message window is invoked so I don't want a million windows to appear!
I can't get the ShellExecuteW(hwnd,"find","",path,shcmd) function to work which I could use in the C++ program to control everything.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Messagebox rturus 8 1,472 Nov-08-2022, 10:40 PM
Last Post: deanhystad
  'No module named tkinter.messagebox' - PyInstaller ironfelix717 7 8,292 Jan-19-2020, 06:56 AM
Last Post: buran

Forum Jump:

User Panel Messages

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