체크박스, 버튼
from select import select
from tabnanny import check
from tkinter import *
root = Tk()
root.title("Python GUI") #title 이름
root.geometry("1280x720+900+100")
chkclick = IntVar() #IntVar : 어떤 의미의 정수값을 초기값으로 넣을거야
chkclick2 = IntVar()
checkBox1 = Checkbutton(root, text="오늘 하루 그만 보기", variable = chkclick) #variable = 변수 , 체크할 값 넣기
checkBox1.pack()
checkBox2 = Checkbutton(root, text="1주일 동안 보지 않기", variable = chkclick2)
checkBox2.pack()
def getCheck():
print("체크 상태", chkclick.get())
Button(root, text= "확인" , command = getCheck).pack()
checkBox1.select() #checkBox가 체크된 상태로 출력됨 , obejct인 경우 체크가 안되므로 주의
checkBox2.deselect()
root.mainloop() #이벤트 체크
콤보 박스
from select import select
import tkinter.ttk as ttk
from tkinter import *
root = Tk()
root.title("Python GUI") #title 이름
root.geometry("1280x720+900+100")
dateVal = [str(i) + "일" for i in range(1,32)] #[1,2,3,4,5]
print(dateVal)
comboBox = ttk.Combobox(root, height=10, values= dateVal, state= "readonly")
comboBox.current(0)
comboBox.pack()
comboBox.set("통장은 거들뿐")
def selectDate():
print(comboBox.get())
Button(root, text = "날짜선택", command = selectDate ).pack()
root.mainloop() #이벤트 체크
해당하는 날짜를 클릭할 경우 터미널에 해당 날짜 출력
from select import select
from tabnanny import check
from tkinter import *
root = Tk()
root.title("Python GUI") #title 이름
root.geometry("1280x720+900+100")
Label (root, text= "햄버거를 선택하세요").pack()
burger_var = StringVar()
btn_burger1 = Radiobutton(root, text = "불고기버거", value="불고기버거", variable=burger_var)
btn_burger2 = Radiobutton(root, text = "치즈버거", value="치즈버거", variable=burger_var)
btn_burger3 = Radiobutton(root, text = "싸이버거", value="싸이버거", variable=burger_var)
btn_burger1.pack()
btn_burger2.pack()
btn_burger3.pack()
btn_burger1.select() #Run 실행시 모든 체크 방지
def order():
print(burger_var.get() + "를 주문하였습니다.")
Button(root, text= "주문", command = order).pack()
root.mainloop() #이벤트 체크
주문하기 클릭한 결과