看板 Python 關於我們 聯絡資訊
使用 Tkinter 當 UI 時,該如何讓未處理的 exception 能停止整個程式呢? 以底下這個程式為例子來說: from Tkinter import * def raiseException(): raise Exception('unhandled exception') root = Tk() Button(root, text = 'Button', command = raiseException).pack() root.mainloop() 使用者按下按鈕後,會產生一個沒人處理的 exception 在 C++,這會導致整個程式崩潰掉 可是在使用 Tkinter 的 python 程式裡,只會在 console 冒出錯誤訊息 程式還是活的好好的 請問要怎樣修改才能讓程式像 C++ 一樣崩潰掉? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.170.57.216
os653:自己找到了,把 root.report_callback_exception 改掉就行了 10/02 00:49