Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ttk.Spinbox missing in tkinter.ttk?

Tags:

python

tkinter

The tkinter version I am using is accessing tk.TclVersion=8.6.

I am able to access stylename='TSpinbox' from ttk.Style().

Stylename = TSpinbox
Layout    = [('Spinbox.field', {'side': 'top', 'sticky': 'we', 'children': [('null', {'side': 'right', 'sticky': '', 'children': [('Spinbox.uparrow', {'side': 'top', 'sticky': 'e'}), ('Spinbox.downarrow', {'side': 'bottom', 'sticky': 'e'})]}), ('Spinbox.padding', {'sticky': 'nswe', 'children': [('Spinbox.textarea', {'sticky': 'nswe'})]})]})]
Element(s) = ['Spinbox.field', 'null', 'Spinbox.uparrow', 'Spinbox.downarrow', 'Spinbox.padding', 'Spinbox.textarea']
Spinbox.field                  options: ('fieldbackground', 'borderwidth')
null                           options: ()
Spinbox.uparrow                options: ('background', 'relief', 'borderwidth', 'arrowcolor', 'arrowsize')
Spinbox.downarrow              options: ('background', 'relief', 'borderwidth', 'arrowcolor', 'arrowsize')
Spinbox.padding                options: ('padding', 'relief', 'shiftrelief')
Spinbox.textarea               options: ('font', 'width')

According to documentation, widget ttk.Spinbox exists. But in Python 3.6.5 tkinter.ttk, such a widget does not exist:

AttributeError: module 'tkinter.ttk' has no attribute 'Spinbox'

May I know when this widget will be made available or which version of Python tkinter.ttk already offers the ttk.Spinbox widget? Thanks.

like image 737
Sun Bear Avatar asked Sep 21 '18 09:09

Sun Bear


1 Answers

You're right, the implementation of the ttk Spinbox was omitted. This has been solved for python 3.7.

You can copy this implementation to do this yourself though:

import tkinter as tk
from tkinter import ttk

class Spinbox(ttk.Entry):

    def __init__(self, master=None, **kw):

        ttk.Entry.__init__(self, master, "ttk::spinbox", **kw)
    def set(self, value):
        self.tk.call(self._w, "set", value)

root = tk.Tk()
s = Spinbox(root, from_=0, to=10)
s.set(5)
s.pack()
root.mainloop()
like image 53
fhdrsdg Avatar answered Nov 15 '22 02:11

fhdrsdg