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:
w = Spinbox( master, option, ... )
here:
master − This represents the parent window.
options − Here is the list of most commonly used options for this widget.
Example:
from Tkinter import *
master = Tk()
w = Spinbox(master, from_=0, to=10)
w.pack()
mainloop()
You can specify a set of values instead of a range:
w = Spinbox(values=(1, 2, 4, 8))
w.pack()
Its options are:
activebackground
The color of the slider and arrowheads when the mouse is over them.
bg
The color of the slider and arrowheads when the mouse is not over them.
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.
command
A procedure to be called whenever the scrollbar is moved.
cursor
The cursor that appears when the mouse is over the scrollbar.
disabledbackground
The background color to use when the widget is disabled.
Tkinter Text Widget
The Text widget provides formatted text display. It allows you to display and edit text with various styles and attributes.
Syntax:
T = Text(root, bg, fg, bd, height, width, font, ..)
Here ,Options:
root – root window.
bg – background colour
fg – foreground colour
bd – border of widget.
height – height of the widget.
width – width of the widget.
font – Font type of the text.
cursor – The type of the cursor to be used.
insetofftime – The time in milliseconds for which the cursor blink is off.
insertontime – the time in milliseconds for which the cusrsor blink is on.
padx – horizontal padding.
pady – vertical padding.
state – defines if the widget will be responsive to mouse or keyboards movements.
highligththickness – defines the thickness of the focus highlight.
insertionwidth – defines the width of insertion character.
relief – type of the border which can be SUNKEN, RAISED, GROOVE and RIDGE.
yscrollcommand – to make the widget vertically scrollable.
xscrollcommand – to make the widget horizontally scrollable.
Some Common methods
index(index) – To get the specified index.
insert(index) – To insert a string at a specified index.
see(index) – Checks if a string is visible or not at a given index.
get(startindex, endindex) – to get characters within a given range.
delete(startindex, endindex) – deletes characters within specified range.
Tag handling methods
tag_delete(tagname) – To delete a given tag.
tag_add(tagname, startindex, endindex) – to tag the string in the specified range
tag_remove(tagname, startindex, endindex) – to remove a tag from specified range
Mark handling methods
mark_names() – to get all the marks in the given range.
index(mark) – to get index of a mark.
mark_gravity() – to get the gravity of a given mark.
Example:
import tkinter as tk
root = Tk()
# specify size of window.
root.geometry("250x170")
# Create text widget and specify size.
T = Text(root, height = 5, width = 52)
# Create label
l = Label(root, text = "Fact of the Day")
l.config(font =("Courier", 14))
Fact = """A man can be arrested in
Italy for wearing a skirt in public."""
# Create button for next text.
b1 = Button(root, text = "Next", )
# Create an Exit button.
b2 = Button(root, text = "Exit",
command = root.destroy)
l.pack()
T.pack()
b1.pack()
b2.pack()
# Insert The Fact.
T.insert(tk.END, Fact)
tk.mainloop()
Output: