我正在學習Microsoft Windows 7中的Python和PyQt5。我的IDE是PyCharm 4.5 CE。如何在使用QFileDialog類時避免父窗口小部件警告?
我想讓用戶的文件對話框可以輕鬆地選擇文件或目錄。
我的代碼...
# coding: utf-8
import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QFileDialog
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.init_gui()
def init_gui(self):
file_names = QFileDialog.getOpenFileNames(self, "Select one or more files to open", "C:/Windows", "")
print(file_names)
self.setGeometry(100, 100, 500, 300)
self.show()
if __name__ == "__main__":
app = QApplication(sys.argv)
mw = MainWindow()
sys.exit(app.exec_())
父母主窗口中有許多按鈕,其中一個按鈕顯示文件對話框。
在這種情況下什麼是正確的父母?
你的代碼是正確的。 PyCharm只是錯了。 – ekhumoro