python - Why does tkinter.ttk Combobox clear displayed value on initial selection only? -
i building gui in tkinter , seeing curious behaviour ttk.combobox
. initializes fine, when select item dropdown, combobox display clears. happens first time make selection. start app > make selection > display clears > make selection > diplays normal. here's code (only pertinent parts brevity). combobox class fetches column database list , assigns values. otherwise, pretty straighforward tkinter.
import tkinter tk tkinter import messagebox tkinter import ttk tkinter import n, s, e, w tkinter import end, center import dbmanager class maingui(tk.tk): """main gui class engcalc.""" def __init__(self, db_mngr): """see class docstring.""" self.db = db_mngr tk.tk.__init__(self) tk.tk.wm_title(self, 'engcalc') self.init_root_frame(master=self) def init_root_frame(self, master=none): """create , initialize main gui container.""" self.root_frame = ttk.frame(master) self.root_frame.grid() dbcombo(master=self.root_frame, controller=self, table='[materials(si)]', col='material') class dbcombo(ttk.combobox): """a dropdown combobox given column in database table.""" def __init__(self, master=none, controller=none, table=none, col=none, row=0, column=0): """see class docstring.""" self.values = controller.db.fetch_list(table, col) self.combovar = tk.stringvar() ttk.combobox.__init__(self, master, values=self.values, textvariable=self.combovar) self.current(0) self.bind("<<comboboxselected>>", self.newselection) self.grid(column=column, row=row) self.state(['!disabled', 'readonly']) def newselection(self, event): """get value of combobox.""" self.combovar = self.get() print(self.combovar) if __name__ == '__main__': db = '../db/test1.sqlite' database = dbmanager.databasemanager(db) foo = maingui(database) foo.mainloop()
at 1 point in code self.combovar
points instance of stringvar
, later redefine self.combovar
string. solution not redefine self.combovar
inside newselection
Comments
Post a Comment