Help, please, adapt the Python script code under Win + Anaconda.

It is necessary to overcome the error.
On Linux, the build code for the Combobox widget from the Tkinter library works, but not on Windows.

Previously googled, but did not find any examples of working with Tk through the call function from the Combobox .

Code:

Initialization:

 def ui(im, nim, im_name): import Tkinter app = Tkinter.Tk() f = Tkinter.Frame(app) f.grid(row=0, column=1, sticky="nw") ... 

Actually, the problem function (unfortunately, I did not write it):

 def _optionmenu(k, v, *options): options = list(options) def trace(*args): try: var.set(options.index(svar.get())) except ValueError: pass try: opt = options[v] except (TypeError, IndexError): v = 0 opt = options[0] var = Tkinter.IntVar(f) var.set(v) svar = Tkinter.StringVar(f) svar.set(options[v]) svar.trace("w", trace) wp = f._w.rstrip(".") + ".c" + svar._name f.tk.call("combobox::combobox", wp, "-editable", 0, "-width", max(len(opt) for opt in options)+3, "-textvariable", svar._name, "-background", "white") f.tk.call(wp, "list", "insert", "end", *options) w = nf.makewidget(f, Tkinter.Widget, wp) return w, var 

Call:

 def optionmenu(*options): return lambda f, v: _optionmenu(f, v, *options) rc = os.path.expanduser("~/.image2gcoderc") constructors = [ ("units", optionmenu(_("G20 (in)"), _("G21 (mm)"))), ... ] vars = {} widgets = {} for j, (k, con) in enumerate(constructors): v = defaults[k] text = texts.get(k, k.replace("_", " ")) lab = Tkinter.Label(f, text=text) widgets[k], vars[k] = con(f, v) lab.grid(row=j, column=0, sticky="w") widgets[k].grid(row=j, column=1, sticky="ew") 

Error executing line:

 f.tk.call("combobox::combobox", wp, "-editable", 0, "-width",.... 

"TclError: invalid command name" combobox :: combobox ""

Then I rewrote it like this:

 f.tk.call("ttk::combobox", wp, "-width",... 

and got an error in the following line:

 f.tk.call(wp, "list", "insert", "end", *options) 

TclError: bad command "list": must be bbox, cget, configure, current, delete, get, icursor, identify, index, insert, instate, select, state, set, validate, or xview

I do not understand what she wants from me, if it was executed without problems in Linux. I admit, in Tkinter is not strong.

  • All the same, I mastered the Tk doc and solved the problem like this: ValCbb = "" for w in options: ValCbb + = "" '+ w + ""' f.tk.call ("ttk :: combobox", wp, "- width ", max (len (opt) for opt in options) +3," -textvariable ", svar._name," -background "," white "," -values ​​", ValCbb) - Alex
  • and removed as unnecessary line: f.tk.call (wp, "list", "insert", "end", * options) - Alex

0