0
votes

How can I do in tkinter something similar to a messagebox, but that doesn't have any buttons, including the close, minimize and maximize buttons on top?

I want it to be in a different window (like a message box), and to be able to update the text and close it only within the code.

Is there a way to do something like that?

1
But when the message box pops up, you would write something, wouldn't you? So don't you need to have control over the closing of the message box? - Miraj50
@Miraj50 I want to be able to close it only within the code, and not by the user - Daniel
But you would need to give some indication to your code that you want to close your message box, right? - Miraj50
@Miraj50 This message is for telling the user that the game is on hold until the second player will connect to the server. So I want the message to close only when the player got a message from the server about the second player. - Daniel
create your own modal Toplevel - AD WAN

1 Answers

0
votes

Make your own. For example:

try: #python3 imports
    import tkinter as tk
except ImportError: #python3 failed, try python2 imports
    import Tkinter as tk

class Popup(tk.Toplevel):
    """modal window requires a master"""
    def __init__(self, master, **kwargs):
        tk.Toplevel.__init__(self, master, **kwargs)
        self.overrideredirect(True)
        self.geometry('300x200+500+500') # set the position and size of the popup

        lbl = tk.Label(self, text="Please wait for other players to join ... ")
        lbl.place(relx=.5, rely=.5, anchor='c')

        # The following commands keep the popup on top.
        # Remove these if you want a program with 2 responding windows.
        # These commands must be at the end of __init__
        self.transient(master) # set to be on top of the main window
        self.grab_set() # hijack all commands from the master (clicks on the main window are ignored)

### demo usage:

def open_popup():
    root.popup = Popup(root)

    # close the popup in 2 seconds
    root.after(2000, close_popup)

def close_popup():
    root.popup.destroy()

root = tk.Tk()
btn = tk.Button(root, text='Open Modal Window', command=open_popup)
btn.pack()
root.mainloop()