你的问题相当平庸,虽然不那么明显。问题不在tinker或pythonnet中,它源于COM线程模型。在
首先,由于您使用的是clr,所以让我们尝试直接使用对话框(不一定要导入tinker模块):# importing pythonnet
import clr
# adding reference (if necessary) to WinForms and importing dialogs
# clr.AddReference('System.Windows.Forms')
from System.Windows.Forms import OpenFileDialog, FolderBrowserDialog
# creating instances of dialogs
folder_dialog = FolderBrowserDialog()
file_dialog = OpenFileDialog()
# try to show any of them
folder_dialog.ShowDialog()
file_dialog.ShowDialog()
如你所见,它就像你的箱子一样挂着。如上所述,原因来自线程的单元状态([1],[2])。在
因此,clr隐式将此状态设置为MTA(多线程单元),可以通过^{}函数对其进行测试:
^{pr2}$
但是,许多较旧的COM对象(如shell对话框)需要STA模式。
关于这两种状态之间区别的很好的解释可以在here或there中找到。在
最后,解决方案:
1)对话框使用STA线程:# impo