본문 바로가기

python

(58)
[Python] 파이썬에서 home 디렉토리 접근하기 [Python] 파이썬에서 home 디렉토리 접근하기 파이썬에서 홈디렉터리에 접근하기 위해서는 아래와 같은 코드를 통해 홈디렉터리 경로를 얻을 수 있다. import oshome_path = os.path.expanduser('~')print (home_path) 출력 :C:\Users\admin 만약 홈디렉터리에 있는 폴더에 접근하고 싶다면 아래와 같이 join함수를 통해 접근할 수 있다. import oshome_path_file = os.path.expanduser(os.path.join('~', 'test.json'))print (home_path_file)출력 :C:\Users\admin\test.json
Python에서 json파일 다루기 (읽기, 쓰기, 수정) Python에서 json파일 다루기 (읽기, 쓰기, 수정) C 드라이브에 아래와 같은 json 형식의 파일이 있다고 가정해보자 C:\test.json{"K5": {"price": "5000","year": "2015"},"Avante": {"price": "3000","year": "2014"}} # json 파일 읽기 해당 파일을 읽기 위해서는 json 모듈을 임포트 한후, load함수를 통해 데이터를 가져올 수 있다. import json with open('C:\\test.json', 'r') as f: json_data = json.load(f)print(json.dumps(json_data) ) 출력 : {"K5": {"price": "5000", "year": "2015"}, "Avante":..
[Python/Pyqt5] 윈도우 스크린 정 가운데에 띄우는 방법 Pyqt5 윈도우 스크린 정 가운데에 띄우는 방법 아래와 같이 center 함수를 정의하고, initUI 부분에서 호출해주면 스크린 정 가운데에 윈도우가 생성된다. import sysfrom PyQt5.QtWidgets import QWidget, QDesktopWidget, QApplication class WinCenter(QWidget): def __init__(self): super().__init__() self.init_UI() def init_UI(self): self.resize(250, 150) self.center() self.setWindowTitle('Center') self.show() def center(self): qr = self.frameGeometry() cp = QDes..
[Python/pyqt] desinger를 통해만든 ui파일 py으로 변경해주는 명령어 파이썬 ui파일 python으로 변경해주는 명령어 Pyqt designer 툴로 만든 ui파일을 python으로 쉽게 변환하기 위해서는 아래와 같은 명령어로 변경할 수 있다. python -m PyQt5.uic.pyuic -x ui파일 경로 -o 파이썬 출력 경로 ex)python -m PyQt5.uic.pyuic -x imade.ui -o imade.py
PyQt에서 label 객체 실시간으로 변경하기 PyQt에서 label 객체 실시간으로 변경하기 pyqt같은 경우 특정 객체의 값이 바뀌어도, 이들이 실시간으로 반영되지 않는다. 다시 그리기위해서는 상위 객체에 다시 그려달라고 요청해야 한다. label 객체같은 경우 repaint()함수를 통해 요청한다. 객체.repaint() ex)self.progLabel.setText("Closing ...")self.progLabel.repaint()