python - New to tkinter tuple has no attribute -
code:
from tkinter import * # constructor syntax is: # optionmenu(master, variable, *values) speed = [ "fast", "medium", "slow" ] master = tk() variable = stringvar(master) variable.set(speed[0]) # default value w =(optionmenu, (master, variable) + tuple(speed)) w.pack() mainloop() error message:
traceback (most recent call last): file "s:/ks4/year 10/computing/python/tkinter.py", line 18, in <module> w.pack() attributeerror: 'tuple' object has no attribute 'pack'
yes, w tuple, indeed can see if print(w):
(<class 'tkinter.optionmenu'>, (<tkinter.tk object @ 0x02f97f30>, <tkinter.stringvar object @ 0x02fae970>, 'fast', 'medium', 'slow')) this two-tuple where:
- the first element
w[0]optionmenuclass object; and - the second element
w[1]tuple, containing 5 elements:- the
mastertkinstance; - the
variablestringvarinstance; and - the 3
strinstancesspeed.
- the
i doubt hoping for. looking @ assignment:
w =(optionmenu, (master, variable) + tuple(speed)) you have comma after class name, makes tuple. contrast working assignment, parentheses open after class name, , close after arguments:
variable = stringvar(master) presumably, wanted:
w = optionmenu(master, variable, *speed) note syntax actually mentioned in code.
Comments
Post a Comment