Skip to content

tkinter.simpledialog.askinteger() conflict with tkinter.filedialog.asksaveasfilename() causing Python interpreter crash on macOS #117620

Description

@rminkler1

Crash report

What happened?

When calling simpledialog to get user input, then later calling filedialog to save a text file, the python interpreter often crashes. Without both dialog boxes called, there is no crash.

Reproducible on macOS Sierra 14.4.1 Macbook Air M1
Could not reproduce on Windows
Python 3.12
ips crash report generated and available

from tkinter import *
from tkinter import filedialog, scrolledtext, simpledialog

# BEGIN CODE THAT CAUSES CRASH ******
# BEGIN CODE THAT CAUSES CRASH ******
# BEGIN CODE THAT CAUSES CRASH ******

# prompt for settings
time_out_seconds = simpledialog.askinteger(title="Title", prompt="Prompt")

# set defaults if dialogs are cancelled
if not time_out_seconds:
    time_out_seconds = 10


# END CODE THAT CAUSES CRASH ********
# END CODE THAT CAUSES CRASH ********
# END CODE THAT CAUSES CRASH ********


def save_to_file():
    """
    Saves File
    """
    # CRASH OCCURS HERE ******
    # CRASH OCCURS HERE ******
    # CRASH OCCURS HERE ******
    # while it does crash without filetypes defined, it crashes more often when filetypes are defined.
    file_path = filedialog.asksaveasfilename(defaultextension=".txt",
                                             filetypes=[("Text files", "*.txt"), ("All files", "*.*")])
    if file_path:
        with open(file_path, 'w') as file:
            text_content = "Sample text document text"
            file.write(text_content)


# Window config
window = Tk()

# User input
text_box = scrolledtext.ScrolledText()
text_box.pack()

# Save Button
save_button = Button(window, text="Save", command=save_to_file)
save_button.pack()

window.mainloop()

CPython versions tested on:

3.12

Operating systems tested on:

macOS

Output from running 'python -VV' on the command line:

2024-04-07 20:30:19.525 Python[3024:88005] WARNING: Secure coding is not enabled for restorable state! Enable secure coding by implementing NSApplicationDelegate.applicationSupportsSecureRestorableState: and returning YES. Process finished with exit code 139 (interrupted by signal 11:SIGSEGV)

Activity

  1. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Apr 8, 2024
  2. erlend-aasland commented on Apr 8, 2024

    @erlend-aasland
    Contributor

    See also #93042.

  3. rminkler1 commented on Apr 8, 2024

    @rminkler1
    Author

    See also #93042.

    This crash has been fixed upstream for Tk 8.6.14, and the
    fix is backported for inclusion in the Python 3.11.7 and 3.12.1 installers: #108693

    Good catch. I was running python 3.12.0 which I thought was the latest release.
    Just updated to 3.12.2 and that seems to have fixed the issue.
    I'm new to using Python and this was the first time I encountered a bug that crashed the Python Interpreter or wasn't caused by my code.
    I also did not realize there were bug fix releases that had not been installed on my machine.
    Thank you and I think this can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    OS-mactopic-tkintertype-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions