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] optionmenu class object; and
  • the second element w[1] tuple, containing 5 elements:
    • the master tk instance;
    • the variable stringvar instance; and
    • the 3 str instances speed.

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

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -