hPyT icon indicating copy to clipboard operation
hPyT copied to clipboard

[BUG] Python crashes when trying to hide the titlebar of a Toplevel while the main window's titlebar is also hidden

Open Valer100 opened this issue 5 months ago • 5 comments

When trying to hide the titlebar of a Toplevel window while the main window's titlebar is also hidden, Python itself crashes without showing an exception. Here's a minimal, reproducible example:

import tkinter as tk, hPyT
from tkinter import ttk

window = tk.Tk()
hPyT.title_bar.hide(window)

def open_toplevel():
    toplevel = tk.Toplevel()
    hPyT.title_bar.hide(toplevel)

    ttk.Label(toplevel, text = "I'm not even displaying").place(relx = 0.5, rely = 0.5, anchor = "center")

ttk.Button(window, text = "Open Toplevel", command = open_toplevel).place(relx = 0.5, rely = 0.5, anchor = "center")

window.mainloop()

When I click on the "Open Toplevel" button, the Toplevel opens, but the app freezes for a few seconds, then it crashes without any exception.

In the Event Viewer, I only get some vague messages about Python crashing, but they don't really explain what made it to crash:

Windows cannot access the file  for one of the following reasons: there is a problem with the network connection, the disk that the file is stored on, or the storage drivers installed on this computer; or the disk is missing. Windows closed the program Python because of this error.

Program: Python
File: 

The error value is listed in the Additional Data section.
User Action
1. Open the file again. This situation might be a temporary problem that corrects itself when the program runs again.
2. If the file still cannot be accessed and
	- It is on the network, your network administrator should verify that there is not a problem with the network and that the server can be contacted.
	- It is on a removable disk, for example, a floppy disk or CD-ROM, verify that the disk is fully inserted into the computer.
3. Check and repair the file system by running CHKDSK. To run CHKDSK, click Start, click Run, type CMD, and then click OK. At the command prompt, type CHKDSK /F, and then press ENTER.
4. If the problem persists, restore the file from a backup copy.
5. Determine whether other files on the same disk can be opened. If not, the disk might be damaged. If it is a hard disk, contact your administrator or computer hardware vendor for further assistance.

Additional Data
Error value: 0x0
Disk type: 0x0
Faulting application name: python.exe, version: 3.11.9150.1013, time stamp: 0x660bda91
Faulting module name: unknown, version: 0.0.0.0, time stamp: 0x00000000
Exception code: 0xc000041d
Fault offset: 0x0000010bc23b0fc1
Faulting process id: 0x2DC8
Faulting application start time: 0x1DBFF1F8383AC35
Faulting application path: C:\Program Files\Python311\python.exe
Faulting module path: unknown
Report Id: 63051254-47a3-40dd-b729-3538c2f7dfb6
Faulting package full name: 
Faulting package-relative application ID: 

If I comment out either the hPyT.title_bar.hide(window) or hPyT.title_bar.hide(toplevel) line, the Toplevel window opens just fine.

Here's a screen recording of what's happening:

https://github.com/user-attachments/assets/d25218e1-583a-4c00-8478-99e3abeab9b0

I can reproduce this bug on both Windows 10 and 11, but not on Windows 8.1 and 7 (using the same code).

Here are more screen recordings from Windows 10, 8.1, and 7:

Windows 10:

https://github.com/user-attachments/assets/07cf2748-2bcb-4c34-8831-1bd22b864cd1


Windows 8.1:

https://github.com/user-attachments/assets/bb16a000-309e-4a69-a9cb-79441b00b6a7


Windows 7:

https://github.com/user-attachments/assets/2d343113-97e4-4c37-87b0-29dca9236c8a

Valer100 avatar Jul 27 '25 18:07 Valer100

👍🏻

Zingzy avatar Jul 27 '25 18:07 Zingzy

I edited my initial message to add more screen recordings regarding this bug from Windows 10, 8.1, and 7

Valer100 avatar Jul 27 '25 18:07 Valer100

I think I found out why: it's because of the code that removes that 6px frame at the top of the window.

If I comment out the following lines from the hPyT.py file (167-169):

        if WINDOWS_VERSION >= 10.0:  # Windows 10 is version 10.0
            globals()[new] = prototype(handle)
            set_window_long(hwnd, GWL_WNDPROC, globals()[new])

the crash no longer occurs when opening the Toplevel window.

And for testing, I also tried removing the check for Windows 10 and higher and I could experience the same crash on both Windows 7 and 8.1.

Python 3.8 crashing on Windows 7

Python 3.12 crashing on Windows 8.1

Valer100 avatar Jul 28 '25 18:07 Valer100

Interesting, thanks for the deep dive @Valer100 I will take a closer look

Zingzy avatar Jul 28 '25 18:07 Zingzy

For the record, if I click on "View problem details" in the crash dialog on Windows 8.1, I get this:

Problem signature:
  Problem Event Name:	APPCRASH
  Application Name:	python.exe
  Application Version:	3.12.6150.1013
  Application Timestamp:	66db6293
  Fault Module Name:	StackHash_5cba
  Fault Module Version:	0.0.0.0
  Fault Module Timestamp:	00000000
  Exception Code:	c000001d
  Exception Offset:	PCH_63_FROM_ntdll+0x00000000000911FA
  OS Version:	6.3.9600.2.0.0.256.48
  Locale ID:	1048
  Additional Information 1:	5cba
  Additional Information 2:	5cbac6a8814cfc67fbc3d5aab2a847c1
  Additional Information 3:	577f
  Additional Information 4:	577fbf71a51f171a5b0fbfcef81e1824

Read our privacy statement online:
  http://go.microsoft.com/fwlink/?linkid=280262

If the online privacy statement is not available, please read our privacy statement offline:
  C:\Windows\system32\en-US\erofflps.txt

Valer100 avatar Jul 29 '25 11:07 Valer100