06. Check Button

The Checkbutton widget is used to display a number of options to a user as toggle buttons. The user can then select one or more options by clicking the button corresponding to each option.

You can also display images in place of text.

 

 

ú   Create

ú   Set the statement

ú   Display

 

¡¼Syntax¡½

Widget_name=tk.Checkbutton(windows_name, text="Display Text", variable=variable_name)

 

¡¼Example¡½

CheckbuttonEnglish = tk.Checkbutton(maiWin, text="English",             

          variable=chkEng)

 

 

 

 

 

 


 

 

 

¡¼¼Ò½º ÇÁ·Î±×·¥¡½

# File Name : gui013_Checkbutton_01.py

import tkinter as tk

from tkinter import ttk

 

# Create instance of Window

mainWin=tk.Tk()

 

# Set title and size

mainWin.title("Check Button Example")

mainWin.geometry("320x240")

 

# Adding a Labels

LabelLang=ttk.Label(mainWin, text="¾ð¾î")

LabelLang.grid(row=0, column=0)

 

# Adding Check Buttons

chkEnglish=tk.IntVar()

CheckbuttonEng=tk.Checkbutton(mainWin, text="¿µ¾î", variable=chkEnglish)

CheckbuttonEng.deselect()

CheckbuttonEng.grid(row=1, column=0, sticky=tk.W)

 

chkKorean=tk.IntVar()

CheckbuttonKorean=tk.Checkbutton(mainWin, text="Çѱ¹¾î", variable=chkKorean)

CheckbuttonKorean.select()

CheckbuttonKorean.grid(row=2, column=0, sticky=tk.W)

 

chkChinese=tk.IntVar()

CheckbuttonChinese=tk.Checkbutton(mainWin, text="Áß±¹¾î", variable=chkChinese)

CheckbuttonChinese.deselect()

CheckbuttonChinese.grid(row=3, column=0,sticky=tk.W)

 

chkFrench=tk.IntVar()

CheckbuttonFrench=tk.Checkbutton(mainWin, text="ÇÁ¶û½º¾î", variable=chkFrench)

CheckbuttonFrench.deselect()

CheckbuttonFrench.grid(row=4, column=0, sticky=tk.W)

 

 

# Adding a Entry Entry Widget

Display=tk.StringVar()

EntryDisplay=ttk.Entry(mainWin,width=50, textvariable=Display)

EntryDisplay.grid(row=5, column=0)

 

 

 

# Event Funtion

def click_me():

    disLang="³»°¡ ÇÒ ¼ö ÀÖ´Â ¾ð¾î: "

    if chkEnglish.get()==1:

        disLang=disLang+"¿µ¾î"

    if chkKorean.get()==1:

        disLang=disLang+" ,Çѱ¹¾î"    

    if chkChinese.get()==1:

        disLang=disLang+" ,Áß±¹¾î"   

    if chkFrench.get()==1:

        disLang=disLang+", ÇÁ¶û½º¾î"    

       

    disLang=disLang+"."     

    EntryDisplay.delete(0,50)

    EntryDisplay.insert(0,disLang)   

 

# Adding a Button

Button1=ttk.Button(mainWin, text="º¸±â", command=click_me)

Button1.grid(row=6, column=0)

 

# Start Window

mainWin.mainloop()