반응형
/*********************************************************************************************************
-- Title : [PyQt4] File Dialog 구현
-- Reference : pythonspot.com
-- Key word : 파이썬 python pyqt qt qt4 gui 파일 오픈 파일 file dialog
*********************************************************************************************************/
# -*- coding: utf-8 -*-
import os
import sys
from PyQt4.QtCore import pyqtSlot
from PyQt4.QtGui import *
# ------------------------------------------
# -- Create window
# ------------------------------------------
myApp = QApplication(sys.argv) # Create an PyQT4 application object.
w = QWidget() # Add menubar, need to use QMainWindow().
w.setWindowTitle('Add FileDialog')
w.resize(300, 240)
# ------------------------------------------
# -- Create a button in the window
# ------------------------------------------
myButton1 = QPushButton('Open Image', w)
myButton1.move(20,80)
# ------------------------------------------
# -- Create file dialog
# ------------------------------------------
filename = QFileDialog.getOpenFileName(w, 'Open File', '/')
print filename
# print file contents
with open(filename, 'r') as f:
print(f.read())
# ------------------------------------------
# -- Show the window and run the app
# ------------------------------------------
w.show()
myApp.exec_()
반응형