tkinter 06 Checkbutton 勾选项
Posted jkn1234
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了tkinter 06 Checkbutton 勾选项相关的知识,希望对你有一定的参考价值。
-
运行结果:https://s1.ax1x.com/2018/04/16/CewO0O.gif
-
# coding=gbk # 运行结果:https://s1.ax1x.com/2018/04/16/CewO0O.gif import tkinter as tk window = tk.Tk() window.title(‘my window‘) window.geometry(‘200x200‘) l = tk.Label(window, bg=‘yellow‘, width=20, text=‘empty‘) l.pack() def print_selection(): if (var1.get() == 1) & (var2.get() == 0): l.config(text=‘I love only Python ‘) elif (var1.get() == 0) & (var2.get() == 1): l.config(text=‘I love only C++‘) elif (var1.get() == 0) & (var2.get() == 0): l.config(text=‘I do not love either‘) 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) c2 = tk.Checkbutton(window, text=‘C++‘, variable=var2, onvalue=1, offvalue=0, command=print_selection) c1.pack() c2.pack() window.mainloop()
以上是关于tkinter 06 Checkbutton 勾选项的主要内容,如果未能解决你的问题,请参考以下文章
如何增加 Checkbutton 的大小 - Tkinter
如何在 Tkinter 中禁用(灰显)一个 Checkbutton?