close
import os
import sys
from PySide6.QtWidgets import QApplication, QFileDialog
"""建立應用程式實體,開啟對話框選取檔案並取得路徑"""
app = QApplication.instance()
if not app:
    app = QApplication(sys.argv)
# Open file dialog
file_name, _ = QFileDialog.getOpenFileName(None, "Select File")
print("Selected file:", file_name)

1. QApplication類別對應QCoreApplication

2. @staticmethod靜態方法,不用建立實體即可以呼叫的方法

    -> 回傳QCoreApplication或None

class QCoreApplication(PySide6.QtCore.QObject):
    @staticmethod
    def instance() -> PySide6.QtCore.QCoreApplication | None: ...

3. getOpenFileName

class QFileDialog(PySide6.QtWidgets.QDialog):
 @staticmethod
    def getOpenFileNames(parent: PySide6.QtWidgets.QWidget | None= ..., caption: str = ..., dir: str = ..., filter: str = ..., selectedFilter: str = ..., options: PySide6.QtWidgets.QFileDialog.Option = ...) -> typing.Tuple[typing.List[str], str]: ...
 

QFileDialog->QDialog->QWidget->(QObject and QPaintDevice)

QPaintDevice -> Shiboken.Object

class QDialog(PySide6.QtWidgets.QWidget):
class QWidget(PySide6.QtCore.QObject, PySide6.QtGui.QPaintDevice):

 

 

全站熱搜
創作者介紹
創作者 me1237guy 的頭像
me1237guy

天天向上

me1237guy 發表在 痞客邦 留言(0) 人氣()