功能:选择复选框,消息提示框会显示相应的勾选信息。
__author__ = 'freedom'
from Tkinter import *
class App(Frame):
def __init__(self,master):
frame = Frame(master)
frame.grid()
self.lab = Label(frame,text = "Please check")
self.lab.grid(row = 0,column = 0,sticky = W)
self.hobby1 = BooleanVar()
self.checkb = Checkbutton(frame,text = "hobby1",variable = self.hobby1,command = self.updata)
self.checkb.grid(row = 1,column = 0,sticky = W)
self.hobby2 = BooleanVar()
self.checkb2 = Checkbutton(frame,text = "hobby2",variable =self. hobby2,command = self.updata)
self.checkb2.grid(row = 2,column = 0,sticky = W)
self.hobby3 = BooleanVar()
self.checkb3 = Checkbutton(frame,text = "hobby3",variable = self.hobby3,command = self.updata)
self.checkb3.grid(row = 3,column = 0,sticky = W)
self.txt = Text(frame,width = 50,height = 5,wrap = WORD)
self.txt.grid(row = 4,column = 0,sticky = W)
def updata(self):
message = ""
if self.hobby1.get() == 1:
message += "Your Hobby is 1\n"
if self.hobby2.get() == 1:
message += "Your Hobby is 2\n"
if self.hobby3.get() == 1:
message += "Your Hobby is 3"
self.txt.delete(0.0,END)
self.txt.insert(0.0,message)
root = Tk()
root.title("choose your hobby")
app = App(root)
root.mainloop()