How to use the fine-tuning box Spinbox of Tkinter
This article mainly introduces the Tkinter fine-tuning frame Spinbox how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that everyone after reading this Tkinter fine-tuning frame Spinbox how to use the article will have a harvest, let's take a look.
The Spinbox control can be used to select a number from a set of data, or to fine-tune a set value.
First of all, prepare fonts and information labels:
# create fontftTimes = Font (family='Times', size=12, weight=BOLD)
# create a label to display message.label_text = StringVar () label = Label (root, textvariable=label_text) label.grid (row=2, column=0, columnspan=2, sticky=E + W)
Generate a Spinbox for text selection:
# value changed handling.def spin_changed (* args): # get current value and set to label. Label_text.set (tb.get ())
# create a Radiobutton for Teacher.tb = Spinbox (root,values= ('Teacher',' Student', 'Worker'), state='readonly', background= "# ffffa0", foreground= "# ff0000", activebackground= "# a0ffa0", command=spin_changed, font=ftTimes) tb.grid (row=0, column=0, columnspan=1, sticky=W)
The spin_changed function is used to handle the representation when the selection changes. It is specified by the command property when building the Spinbox control, and its content is obtained using the get method of Spinbox and set to the label control.
Spinbox specifies an optional collection through the values property. State is specified as' readonly' to restrict user input.
The second Spinbox is a digital fine-tuning box with the following code:
# control variable of value spinbox.vb_var = StringVar () vb_var.set ('0.6')
Def isOkay (text): if text = ='-': return True if len (text) = 0: return True value = int (float (text) * 100) if-100