
- Python Basics
- Python - Home
- Python - Overview
- Python - History
- Python - Features
- Python vs C++
- Python - Hello World Program
- Python - Application Areas
- Python - Interpreter
- Python - Environment Setup
- Python - Virtual Environment
- Python - Basic Syntax
- Python - Variables
- Python - Data Types
- Python - Type Casting
- Python - Unicode System
- Python - Literals
- Python - Operators
- Python - Operator Precedence
- Python - Arithmetic Operators
- Python - Assignment Operators
- Python - Augmented Operators
- Python - Comparison Operators
- Python - Logical Operators
- Python - Bitwise Operators
- Python - Membership Operators
- Python - Identity Operators
- Python - Comments
- Python - User Input
- Python - Numbers
- Python - Booleans
- Python Control Statements
- Python - Control Flow
- Python - Decision Making
- Python - If else
- Python - Match-Case Statement
- Python - for Loops
- Python - for-else Loops
- Python - While Loops
- Python - break Statement
- Python - continue Statement
- Python - pass Statement
- Python Functions & Modules
- Python - Functions
- Python - Default Arguments
- Python - Keyword Arguments
- Python - Keyword-Only Arguments
- Python - Positional Arguments
- Python - Positional-Only Arguments
- Python - Arbitrary Arguments
- Python - Variables Scope
- Python - Function Annotations
- Python - Modules
- Python - Built in Functions
- Python Strings
- Python - Strings
- Python - Slicing Strings
- Python - Modify Strings
- Python - String Concatenation
- Python - String Formatting
- Python - Escape Characters
- Python - String Methods
- Python - String Exercises
- Python Lists
- Python - Lists
- Python - Access List Items
- Python - Change List Items
- Python - Add List Items
- Python - Remove List Items
- Python - Loop Lists
- Python - List Comprehension
- Python - Sort Lists
- Python - Copy Lists
- Python - Join Lists
- Python - List Methods
- Python - List Exercises
- Python Tuples
- Python - Tuples
- Python - Access Tuple Items
- Python - Update Tuples
- Python - Unpack Tuples
- Python - Loop Tuples
- Python - Join Tuples
- Python - Tuple Methods
- Python - Tuple Exercises
- Python Sets
- Python - Sets
- Python - Access Set Items
- Python - Add Set Items
- Python - Remove Set Items
- Python - Loop Sets
- Python - Join Sets
- Python - Copy Sets
- Python - Set Operators
- Python - Set Methods
- Python - Set Exercises
- Python Dictionaries
- Python - Dictionaries
- Python - Access Dictionary Items
- Python - Change Dictionary Items
- Python - Add Dictionary Items
- Python - Remove Dictionary Items
- Python - Dictionary View Objects
- Python - Loop Dictionaries
- Python - Copy Dictionaries
- Python - Nested Dictionaries
- Python - Dictionary Methods
- Python - Dictionary Exercises
- Python Arrays
- Python - Arrays
- Python - Access Array Items
- Python - Add Array Items
- Python - Remove Array Items
- Python - Loop Arrays
- Python - Copy Arrays
- Python - Reverse Arrays
- Python - Sort Arrays
- Python - Join Arrays
- Python - Array Methods
- Python - Array Exercises
- Python File Handling
- Python - File Handling
- Python - Write to File
- Python - Read Files
- Python - Renaming and Deleting Files
- Python - Directories
- Python - File Methods
- Python - OS File/Directory Methods
- Object Oriented Programming
- Python - OOPs Concepts
- Python - Object & Classes
- Python - Class Attributes
- Python - Class Methods
- Python - Static Methods
- Python - Constructors
- Python - Access Modifiers
- Python - Inheritance
- Python - Polymorphism
- Python - Method Overriding
- Python - Method Overloading
- Python - Dynamic Binding
- Python - Dynamic Typing
- Python - Abstraction
- Python - Encapsulation
- Python - Interfaces
- Python - Packages
- Python - Inner Classes
- Python - Anonymous Class and Objects
- Python - Singleton Class
- Python - Wrapper Classes
- Python - Enums
- Python - Reflection
- Python Errors & Exceptions
- Python - Syntax Errors
- Python - Exceptions
- Python - try-except Block
- Python - try-finally Block
- Python - Raising Exceptions
- Python - Exception Chaining
- Python - Nested try Block
- Python - User-defined Exception
- Python - Logging
- Python - Assertions
- Python - Built-in Exceptions
- Python Multithreading
- Python - Multithreading
- Python - Thread Life Cycle
- Python - Creating a Thread
- Python - Starting a Thread
- Python - Joining Threads
- Python - Naming Thread
- Python - Thread Scheduling
- Python - Thread Pools
- Python - Main Thread
- Python - Thread Priority
- Python - Daemon Threads
- Python - Synchronizing Threads
- Python Synchronization
- Python - Inter-thread Communication
- Python - Thread Deadlock
- Python - Interrupting a Thread
- Python Networking
- Python - Networking
- Python - Socket Programming
- Python - URL Processing
- Python - Generics
- Python Miscellenous
- Python - Date & Time
- Python - Maths
- Python - Iterators
- Python - Generators
- Python - Closures
- Python - Decorators
- Python - Recursion
- Python - Reg Expressions
- Python - PIP
- Python - Database Access
- Python - Weak References
- Python - Serialization
- Python - Templating
- Python - Output Formatting
- Python - Performance Measurement
- Python - Data Compression
- Python - CGI Programming
- Python - XML Processing
- Python - GUI Programming
- Python - Command-Line Arguments
- Python - Docstrings
- Python - JSON
- Python - Sending Email
- Python - Further Extensions
- Python - Tools/Utilities
- Python - GUIs
- Python Questions and Answers
- Python - Programming Examples
- Python - Quick Guide
- Python - Useful Resources
- Python - Discussion
Tkinter Spinbox
The Spinbox widget is a variant of the standard Tkinter Entry widget, which can be used to select from a fixed number of values.
Syntax
Here is the simple syntax to create this widget −
w = Spinbox( master, option, ... )
Parameters
master − This represents the parent window.
options − Here is the list of most commonly used options for this widget. These options can be used as key-value pairs separated by commas.
Sr.No. | Options & Description |
---|---|
1 | activebackground The color of the slider and arrowheads when the mouse is over them. |
2 | bg The color of the slider and arrowheads when the mouse is not over them. |
3 | bd The width of the 3-d borders around the entire perimeter of the trough, and also the width of the 3-d effects on the arrowheads and slider. Default is no border around the trough, and a 2-pixel border around the arrowheads and slider. |
4 | command A procedure to be called whenever the scrollbar is moved. |
5 | cursor The cursor that appears when the mouse is over the scrollbar. |
6 | disabledbackground The background color to use when the widget is disabled. |
7 | disabledforeground The text color to use when the widget is disabled. |
8 | fg Text color. |
9 | font The font to use in this widget. |
10 | format Format string. No default value. |
11 | from_ The minimum value. Used together with to to limit the spinbox range. |
12 | justify Default is LEFT |
13 | relief Default is SUNKEN |
14 | repeatdelay Together with repeatinterval, this option controls button autorepeat. Both values are given in milliseconds. |
15 | repeatinterval See repeatdelay. |
16 | state One of NORMAL, DISABLED, or "readonly". Default is NORMAL. |
17 | textvariable No default value. |
18 | to See from. |
19 | validate Validation mode. Default is NONE. |
20 | validatecommand Validation callback. No default value. |
21 | values A tuple containing valid values for this widget. Overrides from/to/increment. |
22 | vcmd Same as validatecommand. |
23 | width Widget width, in character units. Default is 20 |
24 | wrap If true, the up and down buttons will wrap around. |
25 | xscrollcommand Used to connect a spinbox field to a horizontal scrollbar. This option should be set to the set method of the corresponding scrollbar. |
Methods
Spinbox objects have these methods −
Sr.No. | Methods and Description |
---|---|
1 | delete(startindex [,endindex]) This method deletes a specific character or a range of text. |
2 | get(startindex [,endindex]) This method returns a specific character or a range of text. |
3 | identify(x, y) Identifies the widget element at the given location. |
4 | index(index) Returns the absolute value of an index based on the given index. |
5 | insert(index [,string]...) This method inserts strings at the specified index location. |
6 | invoke(element) Invokes a spinbox button. |
Example
Try the following example yourself −
from Tkinter import * master = Tk() w = Spinbox(master, from_=0, to=10) w.pack() mainloop()
When the above code is execduted, it produces the following result −
