Lecture Checkbutton
Lecture
• Views 356
• Comments 0
• Last Updated at 1 month ago
- 윈도우 프로그램
체크버튼
import tkinter as tk
window = tk.Tk()
window.title('My Window')
window.geometry('200x200')
l = tk.Label(window, bg='white', width=20, text='empty')
l.pack()
def print_selection():
if (var1.get() == 1) & (var2.get() == 0):
l.config(text='I love Python ')
elif (var1.get() == 0) & (var2.get() == 1):
l.config(text='I love C++')
elif (var1.get() == 0) & (var2.get() == 0):
l.config(text='I do not anything')
else:
l.config(text='I love both')
var1 = tk.IntVar()
var2 = tk.IntVar()
c1 = tk.Checkbutton(window, text='Python',variable=var1, onvalue=1, offvalue=0, command=print_selection)
c1.pack()
c2 = tk.Checkbutton(window, text='C++',variable=var2, onvalue=1, offvalue=0, command=print_selection)
c2.pack()
window.mainloop()
열 1 | 열 2 | 열 3 | 열 3 |
---|---|---|---|
예 1)
from tkinter import *
win = Tk()
win.geometry("300x200")
win.title('CheckBox 예제')
w = Label(win, text ='Python 수업의 좋은점', font = ('Helvetica', 20, 'bold'))
w.pack()
Checkbutton1 = IntVar()
Checkbutton2 = IntVar()
Checkbutton3 = IntVar()
Button1 = Checkbutton(win, text = "쉽다",
variable = Checkbutton1,
onvalue = 1,
offvalue = 0,
height = 2,
width = 20,
font=('Arial',16,'bold'))
Button2 = Checkbutton(win, text = "숙제가 적다",
variable = Checkbutton2,
onvalue = 1,
offvalue = 0,
height = 2,
width = 20)
Button3 = Checkbutton(win, text = "수업시간이 짧다",
variable = Checkbutton3,
onvalue = 1,
offvalue = 0,
height = 2,
width = 20)
Button1.pack()
Button2.pack()
Button3.pack()
win.mainloop()
Login to write a comment.