Tkinter stores Spinbox’s numerical data in sequence
In fact, instead of setting the initial and final values when using Spinbox, you can also store the values in the sequence data, for example, within a tuple or list, and when clicking the up/down button, it is equivalent to observing the values within the index of the tuple or list.
Tkinter stores Spinbox’s numerical data in sequence Example#1
Store the numeric data in a tuple, and then click the up/down button to observe the execution results.
from tkinter import *
def printInfo(): # Print the displayed value
print(sp.get())
root = Tk()
root.title("apidemos.com")
sp = Spinbox(
root,
# values=(10,38,170,101), # Storing values as a tuple
values=[10,38,170,101], # Store values as a list
command=printInfo
)
sp.pack(pady=10,padx=10)
root.mainloop()
Output:
Execution Results Since the tuple content is (10,38,170,101), the program starts with the value 10, the first click on the up button is 38, and the second click on the up button is 170. you will also see the following results in the Python Shell window.