In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces "how to use the Tkinter check box". In the daily operation, I believe many people have doubts about how to use the Tkinter check box. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about "how to use the Tkinter check box". Next, please follow the editor to study!
Check box CheckButton is also called CheckBox in other development languages, and its function is relatively simple.
First build a label object to display information.
Label = Label (root) label.grid (row=2, column=0, columnspan=2, sticky=E + W)
Prepare an integer variable to set and get the status of the check box.
# control variablecb1_var = IntVar () cb1_var.set (0)
Build a function to handle user actions. This function is called only when the user is operating, but not when the state is modified by the program. The content of this function is to get the value of the variable reflected on the tag.
# A procedure to be called every time# the user changes the state of this checkbutton.def on_check (): label.config (text=cb1_var.get ())
Build the check box. The onvalue and offvalue in the code are used to specify the state values for the selected and unchecked states, respectively.
# create a CheckButton.cb1 = Checkbutton (root,text= "CheckButton", background= "# ffffa0", foreground= "# ff0000", activebackground= "# a0ffa0", activeforeground= "# 0000ff", variable=cb1_var, onvalue=5, offvalue=-5, command=on_check, font=ftiTimes, height=1, width=10) cb1.grid (row=0, column=0, columnspan=2)
Change the state of the check box by changing the value of the variable. It is important to note that the value of the variable must be consistent with onvalue in order to select the check box.
# modify CheckButton status def toggle_by_var (): sel = cb1_var.get () if sel = 0: cb1_var.set (5) # must be consistent with onvalue else: cb1_var.set (0) Button (root, text='toggle by var', command=toggle_by_var) .grid (row=1, column=0, sticky=E+W)
The examples here are only used to illustrate the use of onvalue,offvalue and variable. If you are just switching between check boxes, you can use the toggle method directly.
# modify the CheckButton status def toggle_by_fun (): cb1.toggle () Button (root, text='toggle_by_fun', command=toggle_by_fun) .grid (row=1, column=1, sticky=E+W) by calling the toggle function, so the study on "how to use the Tkinter check box" is over. I hope you can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.