israel-dryer / ttkbootstrap

A supercharged theme extension for tkinter that enables on-demand modern flat style themes inspired by Bootstrap.
MIT License
1.79k stars 363 forks source link

Minimize window while displaying a MessageBox, window cannot be reopened again #485

Open DanDDXuanX opened 10 months ago

DanDDXuanX commented 10 months ago

Desktop (please complete the following information):

ttkbootstrap: 1.10.1 OS: Windows11

Describe the bug

Hello:

I'm writing a application with ttkbootstrap, and I found a issue that I cannot fix by myself.

When a MessageBox is displayed above the root window, if I use keyboard win+D to switch to desktop, or scenarios that MessageBox show with root window minimized, root windows and the MessageBox cannot be show on screen anymore.

I think it's line 89-90 in dialog.py, in method Dialog.show, led to this problem.

        self._toplevel.grab_set()
        self._toplevel.wait_window()

if I remove self._toplevel.grab_set(), this issue can be fix, but the root window will not be disabled while showing a messagebox, and this can lead to a lot of misoperations.

I wonder if there is a better solution here?

To Reproduce

Here I provide a small example to reproduce this issue:

import ttkbootstrap as ttk
from ttkbootstrap.dialogs import Messagebox

root = ttk.Window(size=(300,300))
Messagebox().show_info(message='test')

after run code above, use keyboard win+D to switch to desktop, the root window cannot be reopen again.

Expected behavior

Make the minimized window with dialog can be reopen normally, without affect the performance of other functions.

Screenshots

No response

Additional context

No response

sushi5551011 commented 5 months ago

Hello,I had the same problem when I minimized the window and closed it in the taskbar,the window did not close and cannot be reopened.

import ttkbootstrap as ttk
from ttkbootstrap.dialogs import Messagebox

root_total= ttk.Window()
def on_closing():
    T = Messagebox.show_question(message='close or not?', title="quit", buttons=["close:info", "not:secondary"],parent=root_total,position=(root_total.winfo_x() + root_total.winfo_width() // 2 - 100,root_total.winfo_y() + root_total.winfo_height() // 2 - 100))
    if T == 'close':
        root_total.destroy()
root_total.protocol("WM_DELETE_WINDOW", on_closing)
DanDDXuanX commented 4 months ago

I made a slight modification to this part (dialog.py line 89-90), which seems to temporarily solve the issue. However, this requires Dialog to have the parent parameter.

        if self._parent:
            self._parent.winfo_toplevel().attributes("-disabled", True)
            self._toplevel.wait_window()
            self._parent.winfo_toplevel().attributes("-disabled", False)
            self._parent.winfo_toplevel().lift()
            self._parent.winfo_toplevel().focus_force()
        else:
            self._toplevel.grab_set()
            self._toplevel.wait_window()