i have 2 option menus , contents of 1 updated selecting value other. whilst common situation still can't seem make work. have options update upon selecting item second, updated box throws following error:
self.selectframe['menu'].add_command(label=frame, command=lambda v = self.varframe, l=frame:v.set(1)) attributeerror: 'str' object has no attribute 'set'`
the code declaration of optionmenu in question below:
self.varframe = tk.stringvar() self.frames = ["",""] self.selectframe = tk.optionmenu(botleftframe, self.varframe, *self.frames) self.varframe.set("none selected") self.selectframe.pack(side="left", padx = 5, pady = 10)
in method in same class code:
def runselectionchanged(self,*args): cnxn = pyodbc.connect('driver={microsoft access driver (*.mdb, *.accdb)};dbq=c:\users\public\dbsdetectorbookingsystem.accdb') cursor = cnxn.cursor() cursor.execute("select runfilepath, runid tblruns") rows = cursor.fetchall() row in rows: if row.runfilepath == self.varrun.get(): chosenrunid = row.runid sqlstring = "select localfilepath, runid tblframes runid=?" cursor.execute(sqlstring, str(chosenrunid)) self.userframes = cursor.fetchall() self.frames = ["",""] frame in self.userframes: self.frames.append(frame.localfilepath) newframes = self.frames self.varframe = "" self.selectframe['menu'].delete(0, 'end') frame in newframes: self.selectframe['menu'].add_command(label=frame, command=lambda v = self.varframe, l=frame:v.set(1))
the error thrown when select item menu after has been updated, not understand why sure lambda command gives ability set. have tried various other ways if phrasing command without lambda doesn't seem work.
self.varframe
not normal string
stringvar
, can't set value by
self.varframe = ""
this way replaced stringvar
normal string
, can't use self.varframe.set()
(in error v.set()
)
you have use set()
self.varframe.set("")
Comments
Post a Comment