简体   繁体   English

tkinter.ttk 中缺少 ttk.Spinbox?

[英]ttk.Spinbox missing in tkinter.ttk?

The tkinter version I am using is accessing tk.TclVersion=8.6.我使用的 tkinter 版本正在访问 tk.TclVersion=8.6。

I am able to access stylename='TSpinbox' from ttk.Style() .我可以从ttk.Style()访问 stylename='TSpinbox' 。

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.根据文档,小部件ttk.Spinbox存在。 But in Python 3.6.5 tkinter.ttk , such a widget does not exist:但是在 Python 3.6.5 tkinter.ttk ,这样的小部件不存在:

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?我可以知道这个小部件什么时候可用,或者哪个版本的 Python tkinter.ttk已经提供了ttk.Spinbox小部件? Thanks.谢谢。

You're right, the implementation of the ttk Spinbox was omitted.你说得对,省略了 ttk Spinbox 的实现。 This has been solved for python 3.7 .这已为 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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM