Skip to content

Commit 2a0ad97

Browse files
Improve the simpledialog demo.
Add a button per dialog, a checkbox to toggle classic/themed widgets, and show a bitmap, a detail message and Alt-key button accelerators in the SimpleDialog example. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 14dbb05 commit 2a0ad97

1 file changed

Lines changed: 29 additions & 11 deletions

File tree

‎Lib/tkinter/simpledialog.py‎

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -772,26 +772,44 @@ def _temp_grab_focus(grab, focus=None, destroy=True):
772772

773773
def test():
774774
root = Tk()
775-
def doit(root=root):
775+
use_ttk = tkinter.BooleanVar(root, value=True)
776+
777+
def test_dialog():
776778
d = SimpleDialog(root,
777779
text="This is a test dialog. "
778780
"Would this have been an actual dialog, "
779781
"the buttons below would have been glowing "
780782
"in soft pink light.\n"
781783
"Do you believe this?",
782-
buttons=["Yes", "No", "Cancel"],
784+
buttons=[{'text': 'Yes', 'underline': 0},
785+
{'text': 'No', 'underline': 0},
786+
{'text': 'Cancel', 'underline': 0}],
783787
default=0,
784788
cancel=2,
785-
title="Test Dialog")
789+
title="Test Dialog",
790+
bitmap='question',
791+
detail="Alt+Y, Alt+N and Alt+C work too.",
792+
use_ttk=use_ttk.get())
786793
print(d.go())
787-
print(askinteger("Spam", "Egg count", initialvalue=12*12))
794+
795+
def test_integer():
796+
print(askinteger("Spam", "Egg count", initialvalue=12*12,
797+
use_ttk=use_ttk.get()))
798+
799+
def test_float():
788800
print(askfloat("Spam", "Egg weight\n(in tons)", minvalue=1,
789-
maxvalue=100))
790-
print(askstring("Spam", "Egg label"))
791-
t = Button(root, text='Test', command=doit)
792-
t.pack()
793-
q = Button(root, text='Quit', command=t.quit)
794-
q.pack()
795-
t.mainloop()
801+
maxvalue=100, use_ttk=use_ttk.get()))
802+
803+
def test_string():
804+
print(askstring("Spam", "Egg label", use_ttk=use_ttk.get()))
805+
806+
tkinter.Checkbutton(root, text='Use themed (ttk) widgets',
807+
variable=use_ttk).pack(fill=X)
808+
Button(root, text='SimpleDialog', command=test_dialog).pack(fill=X)
809+
Button(root, text='askinteger', command=test_integer).pack(fill=X)
810+
Button(root, text='askfloat', command=test_float).pack(fill=X)
811+
Button(root, text='askstring', command=test_string).pack(fill=X)
812+
Button(root, text='Quit', command=root.quit).pack(fill=X)
813+
root.mainloop()
796814

797815
test()

0 commit comments

Comments
 (0)