Tkinter "wait_window()" will hang and not spawn window from root with "after_idle()" on MacOS
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu bằng cách chạy trình tái hiện tối thiểu được cung cấp trên macOS, tập trung vào sự tương tác giữa after_idle(), Toplevel.show() và wait_window() của Tkinter. So sánh hành vi với cách khắc phục bằng after() được ghi trong tài liệu và Python 3.9. Được xem là hoàn thành khi cửa sổ được chờ xuất hiện trước cửa sổ gốc mà không bị treo, đồng thời vẫn giữ nguyên giá trị được trả về.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug report
Using Toplevel wait_window() from Tkinter on MacOS via after_idle() before any root windows will cause the process to hang and the windows are never spawned.
Expected behavior
The waited for window (Toplevel) will display before the main window (Root). Once some action is taken on the waited for window, in this case "Press me" button, the root window will be displayed. The user cannot access or see the root window until the "Press me" button is pressed.
Actual behavior
- Using
after_idle()- neither window spawns, application hangs - Using a button to call the waited-for-window from root, the waited-for-window spawns and will return a value to root
- Using
after()andwithdraw/deiconify- expected behavior via workaround
MREs follows:
This will not work due to the waited window being called before the root window is displayed using after_idle.
import tkinter as tk
class MainWindow(tk.Tk):
def __init__(self):
super().__init__()
self.title("Hello")
tk.Label(self, text='Hi there').pack()
self.after_idle(self.waitforit)
self.mainloop()
def waitforit(self):
x = WaitedForWindow(self).show()
print(x)
class WaitedForWindow(tk.Toplevel):
def __init__(self, parent: tk.Tk):
tk.Toplevel.__init__(self, parent)
tk.Button(self, text='Press me', command=self.destroy).pack()
def show(self):
self.deiconify()
self.wait_window()
return True
if __name__ == "__main__":
MainWindow()
Spawning a window (without calling the .show() above) will work fine, but a value cannot be returned of course, and both windows will spawn. Running the same MRE in 3.9.0 works fine.
However, if the main window's class is changed to spawn the waited window via button-press, everything works fine, but the behavior is not what we want:
# self.after_idle(self.waitforit)
tk.Button(self, text="Wait for window", command=self.waitforit).pack()
or by using after() [current workaround] we get the correct behavior via some extra steps.
class MainWindow(tk.Tk):
def __init__(self):
super().__init__()
self.title("Hello")
tk.Label(self, text='Hi there').pack()
self.after(0, self.waitforit)
self.after(0, self.withdraw)
self.mainloop()
def waitforit(self):
x = WaitedForWindow(self).show()
print(x)
self.deiconify()
Your environment
- CPython versions tested on (using MRE 1):
- 3.9.0 (working) [^+]
- 3.10.9 (non-functional) [^]
- 3.11.1 (non-functional) [^+]
- 3.12.0a3 (non-functional) [^]
- ... all 64-bit
- Operating system and architecture: MacOS Mojave 10.14.6 x64 (^), MacOS Monterey 12.6.2 (+)
- Tkinter version: 8.6.12 [^+]
- 3.9.0, 3.11.1 tested in and out of bare virtualenv [^+]
- additional tests from colleagues:
- W11, 3.10.5 (working)
Linked PRs
- gh-152620
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Merge trung bình
- 1 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 558
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/cpython
-
docs pending
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
stdlib type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
build type-bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
stdlib topic-email type-feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Tất cả issue của python/cpython
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
-
🐛 Bug 🔔 Pending processing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
jumpserver/jumpserver#17584 ·