1. Create a Spinbox
From tkinter Import *root = Tk () spinbox (Root). Pack () Root.mainloop ()
2. Set the maximum, minimum, and stride values for the Spinbox
root = Tk () spinbox (root, from_ = 0, #设置最小值 to =, #设置最大值 increment = 5 #设置增量值为5, This is the same as the resolution meaning of scale ). Pack () Root.mainloop ()
3. Set the attribute values, after setting this value, each update value will use the value specified
From tkinter Import *root = Tk () sb = Spinbox (root, values = (0,2,20,40,-1), #显示的第一个值为0, and increments according to the index of the tuple, to the most The latter item will no longer increase increment = 2) sb.pack () print (sb[' values ') #输出值为0 2 40-1root.mainloop ()
4. Print the current content of the Spinbox, which is the displayed value, not the value of values.
From tkinter Import *root = Tk () def printspin (): # Use the Get () method to get the current display value of print (Sb.get ()) sb = Spinbox (Root, From_ = 0, #最小值 to = ten, #最大值 command = printspin# callback function ) Sb.pack () Root.mainloop ()
5. Delete and insert
root = Tk () #作用是删除values第一位def printspin (): sb.delete (0) #在索引位置0处删除 print (Sb.get ()) sb = Spinbox (Root, from_ = 1, #最小值 to = 9999, #最大值 increment = 1, command = Printspin #回调函数 ) # The following two sentences are assigned the initial value of the Spinbox 9988. Read a good document, do not know the correct wording is what, the first to replace the Sb.delete (0) Sb.insert (end,9988) #在索引结尾插入sb. Pack () Root.mainloop ()
Python GUI----Spinbox