In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, the editor will share with you the relevant knowledge about how to use the Tkinter radio button. The content is detailed and the logic is clear. I believe most people still know too much about this, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
Corresponding to the check button is the radio button.
The picture is simple, and the code is just as simple. First build the font and the Label control used to display information.
# create fontftTimes = Font (family='Times', size=12, weight=BOLD)
# create Labellabel_text = StringVar () label = Label (root, textvariable=label_text) label.grid (row=2, column=0, columnspan=2, sticky=E + W)
Prepare a variable to manage the results of the selection and assign an initial value:
# control variablerb_var = StringVar () rb_var.set ('T')
Prepare the first radio button:
# create a Radiobutton for Teacher.rbt = Radiobutton (root,text= "Teacher", background= "# ffffa0", foreground= "# ff0000", activebackground= "# a0ffa0", activeforeground= "# 0000ff", variable=rb_var, value='T', font=ftTimes, height=1) rbt.grid (row=0, column=0, columnspan=1, sticky=W)
Note the use of the variable options variable and value options. If the value of the variable rb_var is the same as the value option, the button is selected.
Using the same method, add a second check box.
# create a Radiobutton for Student.rbs = Radiobutton (root,text= "Student", background= "# ffffa0", foreground= "# ff0000", activebackground= "# a0ffa0", activeforeground= "# 0000ff", variable=rb_var, value='S', font=ftTimes, height=1) rbs.grid (row=1, column=0, columnspan=1, sticky=W)
Radiobutton is grouped in Tkinter by specifying the same variable option. In this case, Student and Teacher both point to the same rb_var variable, so they are a group.
Radiobutton also has the command option, which can be used to specify the processing when the mouse clicks on the control, but this approach requires the same processing for each Rediobutton. It's a little troublesome. Another strategy is used here: monitoring variables. The code is as follows:
Def var_changed (* args): label_text.set (rb_var.get ()) # set variable observer.rb_var.trace_variable ('walled, var_changed)
When a write occurs in rb_var, the var_changed function is called.
These are all the contents of the article "how to use the Tkinter Radio Button". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.
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.