我刚刚学习了Tkinter,并且经历了许多使用预定义值设置组合框的示例,但是当我尝试运行它时,我一直收到错误。
combo ['价值观'] =("私有","商业"," ATP") TypeError:' NoneType'对象不支持项目分配
这是我的代码:
from tkinter import *
from tkinter import ttk
root = Tk()
root.title("Title Here")
root.geometry("250x300")
frame = ttk.Frame(root)
labeltext = StringVar()
labeltext.set("Click the OK button!!") # use the .set option to set the text value
checkboxvar = StringVar()
radiovar = StringVar()
entryVar = StringVar()
comboVar = StringVar()
def changetext():
labeltext.set("thanks")
print("OK button clicked")
return
frame.grid(column=0, row=0, sticky = (N,S,E,W))
ttk.Label(frame, textvariable = labeltext, foreground="red").grid(column=1, row=1, sticky = W)
button1 = ttk.Button(frame, text="OK", default="active", command=changetext).grid(column=2, row=1, sticky = W)
checkbox = ttk.Checkbutton(frame, text="check me", variable = checkboxvar).grid(column=1, row = 3, sticky=W)
rbOne = ttk.Radiobutton(frame, text="One", variable=radiovar, value = "1").grid(column=1, row = 4, sticky = W)
rbTwo = ttk.Radiobutton(frame, text="Two", variable=radiovar, value = "2").grid(column=1, row = 5, sticky = W)
rbThree = ttk.Radiobutton(frame, text="Three", variable=radiovar, value = "3").grid(column=1, row = 6, sticky = W)
entry = ttk.Entry(frame, textvariable=entryVar).grid(column=1, row =7, sticky=W)
combo = ttk.Combobox(frame, textvariable=comboVar).grid(column=1, row =2, sticky=W)
combo['Values'] = ("Private", "Commercial", "ATP")
root.mainloop()