일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- Apple
- Xcode
- graph
- ios
- PyQt
- 그래프
- kotlin
- modal
- TableView
- Chart
- 어플리케이션
- UITableView
- 개발자
- Storyboard
- Swift
- library
- androidstudio
- charts
- UIButton
- PyQt5
- button
- alamofire
- 라이브러리
- UIKit
- 개발
- Python
- Android
- cocoapods
- ui
- Chrats
Archives
- Today
- Total
Jiwift
[Python/PyQt] QCheckBox 체크박스 위젯 / UI 알아보기 본문
반응형
self.[체크박스 이름].stateChanged.connect(기능)
라디오 버튼과 같이 체크박스를 누르면 수행하는 기능을 추가하면 된다.
self.[체크박스 이름].isChecked()
isChecked()를 사용해서 상태 값을 받아올 수 있다.
# 체크 풀기
self.[체크박스위젯 이름].setChecked(False)
# 체크 하기
self.[체크박스위젯 이름].setChecked(True)
체크박스는 라디오 버튼과 다르게 다중 선택이 가능.
사용 예시
# 놀이를 고르는 체크 박스 두개
self.checkBox.stateChanged.connect(self.work)
self.checkBox_2.stateChanged.connect(self.work)
# 음식을 고르는 체크 박스 두개
self.checkBox_3.stateChanged.connect(self.work)
self.checkBox_4.stateChanged.connect(self.work)
# 정보를 담을 리스트. 체크박스 활용은 각자 다릅니다.
self.game = list()
self.food = list()
def work(self):
if self.checkBox.isChecked():
if self.checkBox.text() not in self.game:
self.game.append(self.checkBox.text())
else:
if self.checkBox.text() in self.game:
self.game.remove(self.checkBox.text())
if self.checkBox_2.isChecked():
if self.checkBox_2.text() not in self.game:
self.game.append(self.checkBox_2.text())
else:
if self.checkBox_2.text() in self.game:
self.game.remove(self.checkBox_2.text())
if self.checkBox_3.isChecked():
if self.checkBox_3.text() not in self.food:
self.food.append(self.checkBox_3.text())
else:
if self.checkBox_3.text() in self.food:
self.food.remove(self.checkBox_3.text())
if self.checkBox_4.isChecked():
if self.checkBox_4.text() not in self.food:
self.food.append(self.checkBox_4.text())
else:
if self.checkBox_4.text() in self.food:
self.food.remove(self.checkBox_4.text())
self.label.setText(f"나는 {self.game}가 좋아요. 점심으로 {self.food}를 먹었어요.")
반응형
'다른 개발 > Python' 카테고리의 다른 글
[Python/PyQt] QLineEdit 라인에디트 위젯 / UI 알아보기 (0) | 2022.12.29 |
---|---|
[Python/PyQt] QLabel 레이블 위젯 / UI 알아보기 (0) | 2022.12.29 |
[Python/PyQt] QRadioButton 라디오 버튼 위젯 / UI 알아보기 (0) | 2022.12.29 |
[Python/PyQt] QPushButton 버튼 위젯 / UI 알아보기 (0) | 2022.12.29 |
[Python/PyQt] QFrame 위젯 / UI 알아보기 (0) | 2022.12.29 |