Python GUI編程(Tkinter)8、CheckButton多選框控件


import tkinter

win = tkinter.Tk()
win.title("sunck")
win.geometry("400x400+200+20")

def updata():
message = ""
if hobby1.get() == True:
message += "money\n"
if hobby2.get() == True:
message += "power\n"
if hobby3.get() == True:
message += "people\n"

#清除text中的所有內容
text.delete(0.0, tkinter.END)
text.insert(tkinter.INSERT, message)

#要綁定的變量
hobby1 = tkinter.BooleanVar()
#多選框
check1 = tkinter.Checkbutton(win,text="money", variable=hobby1, command=updata)
check1.pack()
hobby2 = tkinter.BooleanVar()
check2 = tkinter.Checkbutton(win,text="power", variable=hobby2, command=updata)
check2.pack()
hobby3 = tkinter.BooleanVar()
check3 = tkinter.Checkbutton(win,text="people", variable=hobby3, command=updata)
check3.pack()

text = tkinter.Text(win, width=50, height=5)
text.pack()

win.mainloop()


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM