StoryCode

'전체 글'에 해당되는 글 570건

  1. Reference
  2. 설치
  3. Manage Excel

Reference

Python, 파이썬
반응형

http://pyqt.sourceforge.net/Docs/PyQt5/


https://opentutorials.org/module/544/4998

반응형

'Python, 파이썬' 카테고리의 다른 글

설치.DJango + Redis + Celery  (0) 2020.01.29
설치.Windows10.Request Module  (0) 2019.08.06
Manage Excel  (0) 2018.12.03
파이썬 설치시  (0) 2018.06.09
Python 3.6.5 Release  (0) 2018.06.09

설치

Python, 파이썬/GUI 프로그래밍
반응형

2018-650

[ 참조 ] https://www.youtube.com/watch?v=YUdlGBAPNrU&t=1350s


0) Python 3.5.2 로 설치.


1) wxPython, PyQt, TkInter 필요


pip install PyQt5

pip install pyqt5-tools # Python 3.6 혹은 3.7 에서 미지원할 수도 있음.


pip install pyinstaller

> pyinstall main.py


설치 추가 참조 : https://opentutorials.org/module/544/5000


2) PyQT 를 이용하는 방법 두가지

2.1) Qt Designer 사용

2.1.1) 방식1. 생성된 XML 기반의 ui => pyuic5 로 python 파일로 변환

- 디자인 변경시 마다 변환이 귀찮다.


2.1.2) 방식2. 생성된 XML 기반의 ui => loadUi() 메서드 사용

- 변환 없이 바로 사용가능

class Form (QtWidgets QDialog):

  def __init__(self, parent=None):

    QtWidgets.QDialog.__init__(self, parent)


    self.ui = uic.loadui("ui,ui", self)

    self.pb = QtWidgets.QPushButton("test')

    self.pb.show()

   

- 코드로 직접 디자인


3) QWidget

3.1) QWidget 은 가장 기본 위젯

- 즉 모든 위젯은 QWidget 을 피상속 ( 윈도프레임/타이틀, 입력이벤트및 출력처리, 위치/크기등 속성)

- Ex>



QPushButton : 눌리는 버튼모양

QAbstractButton : 클릭 가능해.

QWidget : 기본 위젯


3.2) 시그널과 슬롯

위젯 프로토콜은,

- 모든 위젯은 시그널과 슬롯이 있다.

- 시그널은 정의된 기능이 실행되면 결과 값을 보낸다. (실행할 수 있는 함수가 아니다.)

- 슬롯은 시그널이 보낸값을 받아서 설정된 행위를 한다. (슬롯은 시그널과 연결시켜야 상호간의 통신 가능하다.)


3.3) 사용자 커스텀 위젯

방법1) QWidget 상속

방법2) 다른 Widget 확장


아래 그림)

 - 이미 있는 Widget 상속후 기능추가 변경 =>새로운 시그널 및 슬롯 작성

- 여러 위젯 합쳐서 하나의 위젯으로 만들기



4. 예제)

- 창생성 참조

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/b32b434637e7020b3648205a306dc88881c11cde


- 메뉴바 추가

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/ddb11952dcb00645077e6aa2fc3eb67c96a1ce5a


-국제화 한국어 추가 ( 시스템 로케일 따라 국어 변경 )

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/79aca341cfe995af3c9e728dc0a5e57677cd7956

: 언어 지원이 필요한 문자열에 tr() 함수 사용

: pro 파일제작하여, tr() 이 포함된 파이썬 파일명. 생성할 언어파일명

: pylupdate5 -noobsolete notepad_i18n.pro - 명시된 파일에서 tr() 이 있는 부분을 검사. 국가별 ts 파일 생성

: lrelease.exe "translate\ko_KR.ts" qm파일로 변환

: lrelease.exe는 Qt5 를 설치 또는 pip install PyQt_tools 설치


- 국제화 예제 (언어를 자동 및 수동으로 설정)

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/29617f50b8dfa83b8d4aee35221cc28f5f02c3bc


- 텍스트 에디터 추가 (QTextEdit, 확장성을 위해 사용자 커스텀 위젯화)

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/204815dec080b20d1b82e6c6f040e4b3ed9eca36


- 메뉴 활성화 (새로만들기, 열기, 저장)

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/a36866caac5d1dfdf6b6e5628a7087169ff8feb6


- 상태표시바

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/4c3b3f0d0e60024403d4596f99d477666832ec81



- 프린터 추가

https://github.com/RavenKyu/OpenTutorials_PyQt/commit/ffdba77d5ad044dfc07072d075bb1fbd1e07753b






반응형

Manage Excel

Python, 파이썬
반응형

2018-653


API 참조)

- automatetheboringstuff.com

- openpyxl.readthedocs.io/end/default


1) pip install openpyxl


2)

Python IDLE Shell> import openpyxl

Python IDLE Shell> openpyxl.__version__


3) 

import os

os.chdir('c:\\users\pc1\\desktop')

wb = openpyxl.load_workbook('example.xlsx') // 미리 example.xlsx 를 만들어 둘것. 내용은 아무거나.

type(wb)

wb.get_sheet_names()

sheet = wb.get_sheet_by_name('Sheet1')

type(sheet)

sheet['A1'].value='abcd'

wb.save(example2.xlsx')


sheet.title = "My Sheet"

sheet.cell(row=1, column=3).value


for i in range(2, 5) : print(sheet.cell(row=i, column=3).value)


sheet.max_row

sheet.max_column


openpyxl.cell.get_column_letter(1) // 'A'

openpyxl.cell.column_index_from_string('Z') // 26


wb.create_sheet(title='My Sheet Name', index=1)

wb.save('example4.xlsx')


sheet.row_dimensions[1].height

sheet.row_dimensions[1].height = 70

sheet.column_dimensions['B'].width = 20


from openpyxl.styles import Font

sheet['B1'].font = Font(sz=14, bold=True, italic=True)


import random

for i in range(1, 11) : sheet ['A' + str(i)].value = random.randint(1, 100)


sheet['c8'].value = '=SUM(C1:C7)'


// http://pyautogui.readthedocs.io/en/latest/

// https://pyautogui.readthedocs.io/en/latest/install.html

// pip install pyautogui

import pyautogui

pyautogui.click(100, 100)


반응형

'Python, 파이썬' 카테고리의 다른 글

설치.DJango + Redis + Celery  (0) 2020.01.29
설치.Windows10.Request Module  (0) 2019.08.06
Reference  (0) 2018.12.03
파이썬 설치시  (0) 2018.06.09
Python 3.6.5 Release  (0) 2018.06.09