Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rminkler1 opened this issue Apr 8, 2024 · 2 comments
Labels
OS-mac topic-tkinter type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@rminkler1
Copy link

rminkler1 commented Apr 8, 2024

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)

@rminkler1 rminkler1 added the type-crash A hard crash of the interpreter, possibly with a core dump label Apr 8, 2024
@erlend-aasland
Copy link
Contributor

See also #93042.

@rminkler1
Copy link
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.

@terryjreedy terryjreedy closed this as not planned Won't fix, can't repro, duplicate, stale Apr 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OS-mac topic-tkinter type-crash A hard crash of the interpreter, possibly with a core dump
Projects
None yet
Development

No branches or pull requests

4 participants