菜鸟IT的博客 >> Python
tkinter checkbutton 实战案例
from tkinter import Tk, Checkbutton
main_win = Tk()
main_win.title('渔道的checkbutton控件')
width = 300
height = 300
main_win.geometry(f'{width}x{height}')
def test_cb():
print(lan_c['state'])
print(lan_c['variable'])
print(lan_c['tristatevalue'])
print(lan_c['onvalue'])
print(lan_c['offvalue'])
lan_python = Checkbutton(main_win, text='python', bg='yellow')
lan_c = Checkbutton(main_win, text='c', bg='blue', command=test_cb, relief='raised', bd=5)
lan_c_plus_plus = Checkbutton(main_win, text='c++', bg='yellow', underline=0)
lan_java = Checkbutton(main_win, text='java', bg='blue')
lan_php = Checkbutton(main_win, text='php', bg='yellow')
lan_html5 = Checkbutton(main_win, text='html5', bg='blue')
lan_js = Checkbutton(main_win, text='javascript', bg='yellow')
# 左对齐
lan_python.pack(anchor='w')
lan_c.pack(anchor='w')
lan_c_plus_plus.pack(anchor='w')
lan_java.pack(anchor='w')
lan_php.pack(anchor='w')
lan_html5.pack(anchor='w')
lan_js.pack(anchor='w')
lan_c_plus_plus.select() # 将lan_c_plus_plus设置为选中状态
lan_c_plus_plus.deselect() # 将lan_c_plus_plus设置为未选中状态
lan_c_plus_plus.toggle() # 切换lan_c_plus_plus的状态
main_win.mainloop()
菜鸟IT博客[2022.12.09-00:18] 访问:286