我嘗試使用“pywinauto”包并且它有效。但是當我關閉應用程序時,python 提示一條消息“python 已停止工作”。我sys.coinit_flags = 2按照瓦西里·里亞博夫的建議補充說,警告消失了。from PyQt5.QtWidgets import QApplication, QWidget, QPushButtonimport sysimport warningswarnings.simplefilter("ignore", UserWarning)sys.coinit_flags = 2from pywinauto.application import Applicationfrom pywinauto.keyboard import send_keysclass App(QWidget): def __init__(self): super(App,self).__init__() self.title = 'PyQt5 button - pythonspot.com' self.left = 10 self.top = 100 self.width = 320 self.height = 200 self.setWindowTitle(self.title) self.setGeometry(self.left, self.top, self.width, self.height) button = QPushButton('PyQt5 button', self) button.setToolTip('This is an example button') button.move(100, 70) button.clicked.connect(self.on_click) self.show() def on_click(self): print('PyQt5 button click')def main(): app = QApplication(sys.argv) app.setStyle('Fusion') w = App() sys.exit(app.exec_())if __name__ == '__main__': main()但是,當我嘗試使代碼變得復雜時,如果我單擊第一個組合框以選擇值“ar-prod”,則會再次提示警告消息。這是警告消息。 如果我刪除self.cb1.addItems(['ar-dev', 'ar-prod'])并且不填充第一個組合框,則不會發生錯誤。
1 回答

Smart貓小萌
TA貢獻1911條經驗 獲得超7個贊
sys.coinit_flags = 2
導入 pywinauto 之前需要。就像這里顯示的那樣:https ://github.com/pywinauto/py_inspect/blob/master/py_inspect.py
- 1 回答
- 0 關注
- 209 瀏覽
添加回答
舉報
0/150
提交
取消