Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the tkinter check box in python

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces how to use the tkinter check box in python. The content is very detailed. Interested friends can use it for reference. I hope it will be helpful to you.

The code is as follows:

# tkinter check box operation import tkinter as tkroot = tk.Tk () root.title ('questionnaire') root.geometry ('220x80') # set window size flag_1 = Falseflag_2 = Falseflag_3 = Falselist_content = [' your hobby is:'] hobby_list = ['swimming', 'singing' Def click_1 (): global flag_1 flag_1 = not flag_1 if flag_1: list_content.append (hobby_list [0]) else: list_content.remove (hobby_list [0]) # print ('your hobby is:' List_content) lab_msg ['text'] = list_contentdef click_2 (): global flag_2 flag_2 = not flag_2 if flag_2: list_content.append (hobby_list [1]) else: list_content.remove (hobby_list [1]) # print (' your hobby is:' List_content) lab_msg ['text'] = list_contentdef click_3 (): global flag_3 flag_3 = not flag_3 if flag_3: list_content.append (hobby_list [2]) else: list_content.remove (hobby_list [2]) # print (' your hobby is:' List_content) lab_msg ['text'] = list_content''' forms Control''# the title shows lab = tk.Label (root, text=' Please choose your hobby:') lab.grid (row=0, columnspan=3, sticky=tk.W) # Multi-box frm = tk.Frame (root) ck1 = tk.Checkbutton (frm, text=' Swimming', command=click_1) ck2 = tk.Checkbutton (frm, text=' singing', command=click_2) ck3 = tk.Checkbutton (frm, text=' Travel' Command=click_3) ck1.grid (row=0) ck2.grid (row=0, column=1) ck3.grid (row=0, column=2) frm.grid (row=1) lab_msg = tk.Label (root, text='') lab_msg.grid (row=2, columnspan=3, sticky=tk.W) root.mainloop ()

Screenshot:

On the python tkinter check box operation is how to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report