mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-42721: Improve using simple dialogs without root window (GH-23897)
When simple query dialogs (tkinter.simpledialog), message boxes (tkinter.messagebox) or color choose dialog (tkinter.colorchooser) are created without arguments master and parent, and the default root window is not yet created, a new temporary hidden root window will be created automatically. It will not be set as the default root window and will be destroyed right after closing the dialog window. It will help to use these simple dialog windows in programs which do not need other GUI. Previously, message boxes and color chooser created the blank root window and left it after closing the dialog window, and query dialogs just raised an exception. Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>
This commit is contained in:
parent
586f3dbe15
commit
675c97eb6c
7 changed files with 144 additions and 24 deletions
38
Lib/tkinter/test/test_tkinter/test_messagebox.py
Normal file
38
Lib/tkinter/test/test_tkinter/test_messagebox.py
Normal file
|
@ -0,0 +1,38 @@
|
|||
import unittest
|
||||
import tkinter
|
||||
from test.support import requires, run_unittest, swap_attr
|
||||
from tkinter.test.support import AbstractDefaultRootTest
|
||||
from tkinter.commondialog import Dialog
|
||||
from tkinter.messagebox import showinfo
|
||||
|
||||
requires('gui')
|
||||
|
||||
|
||||
class DefaultRootTest(AbstractDefaultRootTest, unittest.TestCase):
|
||||
|
||||
def test_showinfo(self):
|
||||
def test_callback(dialog, master):
|
||||
nonlocal ismapped
|
||||
master.update()
|
||||
ismapped = master.winfo_ismapped()
|
||||
raise ZeroDivisionError
|
||||
|
||||
with swap_attr(Dialog, '_test_callback', test_callback):
|
||||
ismapped = None
|
||||
self.assertRaises(ZeroDivisionError, showinfo, "Spam", "Egg Information")
|
||||
self.assertEqual(ismapped, False)
|
||||
|
||||
root = tkinter.Tk()
|
||||
ismapped = None
|
||||
self.assertRaises(ZeroDivisionError, showinfo, "Spam", "Egg Information")
|
||||
self.assertEqual(ismapped, True)
|
||||
root.destroy()
|
||||
|
||||
tkinter.NoDefaultRoot()
|
||||
self.assertRaises(RuntimeError, showinfo, "Spam", "Egg Information")
|
||||
|
||||
|
||||
tests_gui = (DefaultRootTest,)
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_unittest(*tests_gui)
|
Loading…
Add table
Add a link
Reference in a new issue