Python basic
  • Python 기초 수업
  • Python 설치
  • Python의 기본
    • Python 시작하기
    • 변수(Variable)
    • 산술 연산자
    • 문자열(String) 출력
    • 문장(Statement)
  • 자료형
    • 정수형(Integer)
    • 실수형(Float)
    • 부울형(Bool)
    • 복소수형(Complex)
    • 문자열형(String)
  • 조건문
  • 자료구조
    • List
    • Set
    • 튜플(Tuple)
    • 딕셔너리(Dictionary)
  • 반복문
  • 문제 타임
  • 함수(Function)
    • 기본형 함수
    • 매개변수(Parameter)와 반환값(Return Value)
    • 가변매개변수 함수
    • 함수 설명 표시
    • 변수의 범위
  • 모듈(Module)
    • 모듈의 이용
    • __name__ 그리고 '__main__'
  • 예외처리(Exception Handling)
    • try, except, else, finally
  • 클래스(Class)
    • Class 심화
  • PyQt
    • PyQt 설치
    • PyQt Widget
      • QWidget
      • QLabel
      • QLineEdit
      • QTextEdit
      • QPushButton
      • QCheckBox
      • Application Make
        • Widget의 배치 #1
        • Widget의 배치 #2
        • 숫자 맞추기 게임
        • 야구게임
  • OPEN API(공공데이터 포탈)
    • 공공데이터 사용하기
  • 크롤링 (Crawling)
    • Crawling Library 설치
    • 날씨, 미세먼지 농도
  • SQLlite
    • DB의 작성
  • Dic 참고
  • 함수 참고 코드
  • Widget 배치 시작 코드
  • 야구게임
Powered by GitBook
On this page
  • 생성
  • 글자크기 조절
  • 수정되지 않도록 막기
  • 글작 색 변경 및 크기 변경
  1. PyQt
  2. PyQt Widget

QLineEdit

한줄만 사용하는 글자 입력 위젯

생성

# -*- coding: UTF-8 -*-
import sys
from PyQt5.QtWidgets import *

class App(QLineEdit) :
    def __init__(self):
        super(App, self).__init__()
        self.setWindowTitle('Window!!!')
        self.resize(600,600)
        self.setText('한줄 입력창입니다.')

if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = App()
    window.show()
    sys.exit(app.exec_())

이전 위젯 생성과 큰 차이가 없습니다.

글자크기 조절

# -*- coding: UTF-8 -*-
import sys
from PyQt5.QtWidgets import *
from PyQt5 import QtGui
from PyQt5.QtCore import Qt
class App(QLineEdit) :
    def __init__(self):
        super(App, self).__init__()
        self.setWindowTitle('Window!!!')
        self.resize(600,600)
        self.changeFont()
        self.setText('한줄 입력창입니다.')
    def changeFont(self):
        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(45)
        self.setFont(font)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = App()
    window.show()
    sys.exit(app.exec_())

수정되지 않도록 막기

# -*- coding: UTF-8 -*-
import sys
from PyQt5.QtWidgets import *
from PyQt5 import QtGui
from PyQt5.QtCore import Qt
class App(QLineEdit) :
    def __init__(self):
        super(App, self).__init__()
        self.setWindowTitle('Window!!!')
        self.resize(600,600)
        self.changeFont()
        self.setText('한줄 입력창입니다.')
        self.setReadOnly(True)
    def changeFont(self):
        font = QtGui.QFont()
        font.setBold(True)
        font.setPointSize(45)
        self.setFont(font)
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = App()
    window.show()
    sys.exit(app.exec_())

13 setReadOnly(True) 옵션을 추가하면 수정불가한 QLineText가 생성됩니다.

글작 색 변경 및 크기 변경

앞서 글자 크기 변경은 클레스와 함수를 이용했습니다. 지금 사용하는 방법은 StyleSheet를 이용한 방법입니다.

# -*- coding: UTF-8 -*-
import sys
from PyQt5.QtWidgets import *
from PyQt5 import QtGui
from PyQt5.QtCore import Qt
class App(QLineEdit) :
    def __init__(self):
        super(App, self).__init__()
        self.setWindowTitle('Window!!!')
        self.resize(600,600)
        self.setStyleSheet('color:red;font-size:45px;')
        self.setText('한줄 입력창입니다.')
if __name__ == '__main__':
    app = QApplication(sys.argv)
    window = App()
    window.show()
    sys.exit(app.exec_())

13 color:red 글자 색을 빨간 색으로 설정합니다. font-size:45px 글자 크기를 설정합니다. 설정값은 ;(세미콜론)으로 구분합니다.

StyleSheet에 관해서는 다른 장에서 자세히 다루도록 하겠습니다.

PreviousQLabelNextQTextEdit

Last updated 6 years ago