我现在有了一个工作的spinbox,但是我找不到如何获得spinbox的值。当我在互联网上找不到这些例子的时候,有人能帮我吗?
这就是我现在所拥有的。
spinbox = StringVar()
s = ttk.Spinbox(root, from_=1.0, to=100.0, textvariable=spinbox).grid(column=4, row=1, sticky=W)
ttk.Label(root, text="amount:").grid(column=3, row=1, sticky=W)只需在控制台中打印数字就足够了。
谢谢,
发布于 2020-12-23 19:21:16
问题是SpinBox.grid()不返回任何东西,也就是返回None。
所以你可以这样做:
s = ttk.Spinbox(root, from_=1.0, to=100.0, textvariable=spinbox)
s.grid(column=4, row=1, sticky=W)
print(s.get())编辑-添加函数以获取值并将该函数添加到命令参数
def get_spinbox_val():
global s
print(s.get())
s = ttk.Spinbox(root, from_=1.0, to=100.0, textvariable=spinbox, command=get_spinbox_val)
s.grid(column=4, row=1, sticky=W)https://stackoverflow.com/questions/65423252
复制相似问题