简体   繁体   English

如何在 Python Tkinter 的 Spinbox 中包含变量列表

[英]How to include a list of variables in a Spinbox in Python Tkinter

I'm trying to create a Spin-box using Tkinter in Python that contains days of the month ( strings ), yet only know how to include numbers in a range.我正在尝试使用 Python 中的 Tkinter 创建一个包含一个月中的天数(字符串)的 Spin-box,但只知道如何在一个范围内包含数字。 eg;例如; from_ = 1900, to = 2016 . from_ = 1900, to = 2016

How can I include a list of strings in the spin box?如何在旋转框中包含字符串列表? do I need to create an actual list?我需要创建一个实际列表吗?

Here is the specific code:下面是具体代码:

w = StringVar()
Spinbox(root, from_ = 1900, to = 2017, textvariable = w, width = 5).place(x = 315, y = 60)

Just pass a list of strings to the values option of the spinbox:只需将字符串列表传递给 spinbox 的values选项:

from tkinter import Tk, Spinbox
root = Tk()
months = ["January", "February", "March"]
spinbox = Spinbox(root, values=months)
spinbox.pack()
root.mainloop()

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

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