목록랭귀지 (525)
아미(아름다운미소)
PyQt5 QInputDialog 다이얼로그팝업 #-*- coding: utf-8 -*- ''' Created on 2018. 12. 10. @author: bhm ''' from PyQt5.QtWidgets import (QInputDialog, QApplication) app = QApplication([]) dialog = QInputDialog() dialog.show() app.exec_()
Python PyQt5 submenu Python PyQt5 서브메뉴 예제 # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets import QMainWindow, QAction, QMenu, QApplication class Example(QMainWindow): def __init__(self): super().__init__() self.initUI() def initUI(self): menubar = self.menuBar() fileMenu = menubar.addMenu('파일') impMenu = QMenu('열기', self) impAct = QAction('서브메뉴열기', self) impMenu.addAction(impAct) newAct ..
python CSV 파일 쓰기 CSV 파일을 쓰기 위해서는 .csv 파일을 쓰기모드로 오픈하고 파일객체를 csv.writer(파일객체) 에 넣으면 됩니다. CSV writer는 writerow() 라는 메서드를 통해 list 데이타를 한 라인 추가하게 됩니다. 윈도우즈의 경우 csv 모듈에서 데이타를 쓸 때 각 라인 뒤에 빈 라인이 추가되는 문제가 있는데, 이를 없애기 위해 (파이썬 3 에서) 파일을 open 할 때 newline='' 와 같은 옵션을 지정합니다 (주: 파이썬 2의 경우는 newline 옵션 없이 바이너리 모드로 오픈할 것). 아래 예제는 Book1.csv 라는 CSV 파일에 2개 라인을 추가하는 예입니다. #-*- coding: utf-8 -*- ''' Created on 2018. 1..
QHeaderView의 헤더를 클릭하면 QTableView를 정렬하는 방법입니다. 다음 과 같은 함수를 DataFrame사용하면 올바르게 정렬됩니다. def sort(self, Ncol, order): """Sort table by given column number.""" self.layoutAboutToBeChanged.emit() self.data = self.data.sort_values(self.headers[Ncol], ascending=order == Qt.AscendingOrder) self.layoutChanged.emit()
python 서버 시간 확인하기 response 메시지 헤더에 있는 서버 시간정보 값을 가져옵니다. strptime() : 문자열을 날짜/시간으로 변환 mktime() : 일시를 초 단위 시간으로 변환 #-*- coding: utf-8 -*- import urllib.request import urllib.error import time date = urllib.request.urlopen('http://www.google.com').headers['Date'] print(date) time = int(time.mktime(time.strptime(date, '%a, %d %b %Y %H:%M:%S %Z'))) print(time) Tue, 04 Dec 2018 07:38:24 GMT 1543876704
python PyQt5 현재시간 #-*- coding: utf-8 -*- ''' Created on 2018. 12. 3. @author: bhm ''' from PyQt5.QtCore import QTime current_time = QTime.currentTime() text_time = current_time.toString("hh:mm:ss") time_msg = "현재시간: " + text_time print(time_msg) 현재시간: 13:14:46
현상: 이클립스(eclipse.exe)를 실행했을 때 로딩화면 (혹은 로고) 이 깜빡 하더니 금방 사라지는 현상 메모리(힙 메모리 (Heap memory))를 줄여줍니다. 힙 메모리는 동적으로 할당하는 메모리라고도 할 수 있습니다. 이클립스를 실행하면 기본적으로 잡고가는 메모리가 있는데 이 설정이 eclipse.ini 파일에 저장되어 있습니다. 이 부분을 조정합니다. 1. 이클립스가 설치된 폴더로 이동하여 ini 파일 찾기 이클립스가 설치된 폴더로 이동합니다. 저는 C:\eclipse에 위치하고 있습니다. 경로는 누구나 다를 수 있기 때문에 각자 설치된 이클립스 폴더로 이동하면 된니다. eclipse.ini 파일은 바로 이곳에 루트에 위치하고 있습니다. 2. eclipse.ini 파일에 Xms, Xmx ..
stylesheet를 사용하지 않고 색상을 변경할 수 있습니다. Palette= QtGui.QPalette() Palette.setColor(QtGui.QPalette.Text, QtCore.Qt.red) self.lineEdit.setPalette(Palette)
subprocess 모듈을 이용한 명령어 실행 #-*- coding: utf-8 -*- import subprocess subprocess.Popen('.\folder\program.exe')
PyQt5 , QAction 사용하여 menubar 만들기 #-*- coding: utf-8 -*- ''' Created on 2018. 11. 29. @author: bhm ''' from PyQt5.QtWidgets import QMainWindow, QAction, qApp, QApplication from PyQt5.QtGui import QIcon class Example(QMainWindow): def __init__(self): super().__init__() exit_action = QAction(QIcon('exit.png'), "&Exit", self) # exit_action = QAction('&Exit', self) exit_action.setShortcut('Ctrl+Q') e..