pyqt点击按钮打开word文档
时间: 2024-01-24 15:15:39 浏览: 25
以下是使用PyQt实现点击按钮打开Word文档的示例代码:
```python
from PyQt5.QtWidgets import QApplication, QMainWindow, QPushButton
from PyQt5.QtGui import QIcon
import sys
import os
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Open Word Document")
self.setGeometry(100, 100, 300, 200)
button = QPushButton("Open Word", self)
button.setGeometry(100, 80, 100, 30)
button.clicked.connect(self.open_word)
def open_word(self):
os.startfile("path/to/your/word/document.docx")
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
```
请注意,你需要将"path/to/your/word/document.docx"替换为你实际的Word文档路径。