반응형
1. Checkbutton / 체크박스
2. IntVar() : 변수 타입지정 정수형 (필수)
3. variable=var : 타입지정 변수 적용
4. button command = show 함수 호출
5. Label에 체크박스(0/기본, 1/첫번째체크박스값) 표기하기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
from tkinter import *
root = Tk()
root.title('checkbox study')
root.geometry("400x400")
def show():
Label(root, text=var.get()).pack()
var = IntVar()
c = Checkbutton(root, text='체크박스', variable=var)
c.pack()
my_button = Button(root, text='클릭', command=show).pack()
my_label = Label(root, text=var.get()).pack()
root.mainloop()
|
cs |
[지정한 문자값 받아오기]
1. StringVal() : 변수 타입지정 문자형 (필수)
2. Checkbutton 속성
# onvalue = 'on' : 체크박스가 선택되어 있을때 'on' 값을 리턴
# offvalue = 'off' : 체크박스가 해제되어 있을때 'off' 값을 리턴
# 아무것도 선택이 안되어 있을때 이벤트 발생시 '0'을 문자형으로 리턴
3. deselect() : 체크박스 기본값을 해제 (이것을 하지 않으면 체크오류가 있음)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
from tkinter import *
root = Tk()
root.title('checkbox study')
root.geometry("400x400")
def show():
Label(root, text=var.get()).pack()
var = StringVar()
c = Checkbutton(root, text='체크박스', variable=var, onvalue='on', offvalue='off')
c.deselect()
c.pack()
my_button = Button(root, text='클릭', command=show).pack()
my_label = Label(root, text=var.get()).pack()
root.mainloop()
|
cs |
반응형
'파이썬 (pythoon)' 카테고리의 다른 글
[pyhton] tkinter / Scrollbar / Listbox / 리스트박스 / 스크롤바 / 연결하기 (0) | 2021.07.17 |
---|---|
[python] tkinter / DropDownMenu / 드롭다운메뉴 (0) | 2021.07.16 |
[python] tkiniter/ Scale / 슬라이더 위젯 / 화면창 조절하기 / (0) | 2021.07.16 |
[python] tkinter / filedialog / 찾아보기 / 창열기 / 파일선택 / 불러오기 / (0) | 2021.07.16 |
[python] tkinter / Radiobutton / 라디오버튼 / set() / IntVal() / StrVal() / type변수선언 / variable / get() (0) | 2021.07.16 |