Python Forum
[Tkinter] Modal window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Modal window
#7
If all you want to do is display a block of text and an ok button, look at tkinter.dialog.Dialog, the parent class for tkinter common dialogs.
import tkinter as tk
from tkinter.dialog import Dialog, DIALOG_ICON


class Window(tk.Tk):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.title("Basic Dialog Demo")
        tk.Button(
            self, text='Push me! Push me! Push me!', command=self.opendialog
        ).pack(padx=80, pady=(100, 10))


    def opendialog(self):
        with open(__file__, "r") as file:
            text = file.read()

        Dialog(
            self,
            title="Popup Dialog",
            text=text,
            bitmap=DIALOG_ICON,
            default=0,
            strings=("OK",)
        )
        print("Dialog closed.")


Window().mainloop()
Reply


Messages In This Thread
Modal window - by DPaul - Oct-15-2023, 06:51 AM
RE: Modal window - by menator01 - Oct-15-2023, 09:06 AM
RE: Modal window - by DPaul - Oct-15-2023, 09:51 AM
RE: Modal window - by Gribouillis - Oct-15-2023, 09:58 AM
RE: Modal window - by menator01 - Oct-15-2023, 10:01 AM
RE: Modal window - by Larz60+ - Oct-15-2023, 01:11 PM
RE: Modal window - by deanhystad - Oct-15-2023, 03:06 PM
RE: Modal window - by DPaul - Oct-15-2023, 05:21 PM
RE: Modal window - by DPaul - Oct-16-2023, 03:08 PM
RE: Modal window - by deanhystad - Oct-16-2023, 07:13 PM
RE: Modal window - by DPaul - Oct-17-2023, 07:11 AM
RE: Modal window - by deanhystad - Oct-17-2023, 09:40 AM
RE: Modal window - by DPaul - Oct-17-2023, 12:17 PM
RE: Modal window - by deanhystad - Oct-17-2023, 01:19 PM
RE: Modal window - by DPaul - Oct-18-2023, 06:11 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 742 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  tkinter window and turtle window error 1885 3 6,843 Nov-02-2019, 12:18 PM
Last Post: 1885
  Closing Modal Window in QT nieselfriem 0 4,758 Apr-19-2017, 03:32 PM
Last Post: nieselfriem
  update a variable in parent window after closing its toplevel window gray 5 9,232 Mar-20-2017, 10:35 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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