-1

In python, we can create a pop window by define

def pop(msg):
    MessageBox = ctypes.windll.user32.MessageBoxW
    MessageBox(None, msg, 'Window title', 0)

then

pop('some message')

will give a pop up window to notify users.

But how to make this pop up window on top of all other windows, so users can absolutely not miss it?

user15964
  • 2,507
  • 2
  • 31
  • 57

2 Answers2

2

Try:

MessageBox(None, msg, 'Window title', 0x40000)
DirtyBit
  • 16,613
  • 4
  • 34
  • 55
0

It'd probably be a better idea to use tkinter - in addition for it being part of python, it's also cross platform.

Here's an example pop up:

from tkinter import messagebox, Toplevel, Label, Tk, Button


def pop(msg):  # This will be on top of the window which called this pop up
    messagebox.showinfo('message', msg)


def pop_always_on_top(msg):  # This will be on top of any other window
    msg_window = Toplevel()
    msg_window.title("Show Message")
    msg_window.attributes('-topmost', True)
    msg_label = Label(msg_window, text=msg)
    msg_label.pack(expand=1, fill='both')
    button = Button(msg_window, text="Ok", command=msg_window.destroy)
    button.pack()


if __name__ == '__main__':
    top = Tk()

    hello_btn = Button(top, text="Say Hello", command=lambda: pop('hello world!'))
    hello_btn.pack()
    hello_btn = Button(top, text="Say Hello and stay on top!", command=lambda: pop_always_on_top('hello world - on top!'))
    hello_btn.pack()
    top.mainloop()

The message box is automatically on top of its parent window.

If you want to make it on top of every other window on the system, set the '-topmost' flag of your window (as the second method demonstrates).

feature_engineer
  • 1,088
  • 8
  • 16