def insert(self,database=None): if database==None: database = Database(self.dbname_entry_sv.get()) dbclass = dbtblfactory(self.tblname_entry_sv.get()) for x in range(1,self.maxnewrows): dm={} emptyrow=True for y in range(self.maxcols): colname = self.newrowgrid.widgets[0][y].sv.get() value = self.newrowgrid.widgets[x][y].sv.get() if colname <> "" and colname.startswith("_") == False: if value <> "": dm[colname] = value emptyrow=False if emptyrow == False: dbobj = dbclass.datamembers(database=database,dm=dm) with database: try: exec_str,result = dbobj.persist() log.log(thisfuncname(),4,func=dbobj.persist,exec_str=exec_str,result=result) except Exception, e: log.log(thisfuncname(),1,func=dbobj.persist,error=str(e))
def setUp(self): self.database = Database(CURRENTDIR + "/" + THISEXEC + "/" + 'test_sswizard') self.classtbl = 'class' self.maxx = 8 self.maxy = 10
def color_db_load(dbname="test_ssloader"): tblname = "colors" colors_col_defn = [('name', 'text'), ('hex', 'text'), ('rgb', 'text'), ('__id', 'text'), ('__timestamp', 'text')] colors_col_names = [row[0] for row in colors_col_defn] dbrows = [] for key, value in colors.attr_get_keyval(include_callable=False, include_baseattr=False): rgb = hex2rgb(value) rgbstr = ",".join(map(str, rgb)) __id = IDGenerator().getid() __timestamp = datetime.now().strftime("%H:%M:%S") dbrows.append([ "\"" + key + "\"", "\"" + value + "\"", "\"" + rgbstr + "\"", "\"" + __id + "\"", "\"" + __timestamp + "\"" ]) database = Database(dbname) with database: if tbl_exists(database, tblname) == True: tbl_remove(database, tblname) tbl_create(database, tblname, colors_col_defn) exec_str, result = tbl_rows_insert(database, tblname, colors_col_names, dbrows)
def setUp(self): self.databasename = CURRENTDIR + "/" + THISEXEC + "/" + "quad" self.database = Database(self.databasename) self.cols = ['col1', 'col2'] self.rows = [['val1', 'val2']]
def __init__(self, databasename, buckets=DEFAULT_BUCKETS): self.databasename = databasename try: self.database = Database(self.databasename) except Exception, e: log.log(PRIORITY.FAILURE, msg="database [" + self.databasename + "] does not exist") exit()
def _write_to_db(self, row, dname, tname, cdefn, cnames): database = Database(dname) with database: if tbl_exists(database, tname) == False: tbl_create(database, tname, cdefn) tbl_rows_insert(database, tname, cnames, row)
def test_1file_no_limits(self): self.tcxparser.persist(self.test_file_name) database = Database('foo',True) with database: _,rows,_ = tbl_rows_get(database,'foo') self.assertListEqual(self.expected_results,rows)
def test(self): self.tcxparser.persist(self.test_file_name2) database = Database('foo',True) with database: _,rows,_ = tbl_query(database,'select count(*) from foo where filename=\"'+os.path.splitext(self.test_file_name2)[0]+'\"') self.assertEqual(200,rows[0][0])
def test_1file_no_limits_fail_to_write_to_db(self): self.tcxparser.persist(self.test_file_name, column_names =["id","foobar","watts","hr","filename"]) database = Database('foo',True) with database: _,rows,_ = tbl_rows_get(database,'foo') self.assertListEqual([],rows)
def dbcolors_get(dbname): results = {} database = Database(dbname) with database: _, colors, _ = _colorexecfunc(database) for color in colors: results[color[0]] = color[1] return (enum(**results))
def dbformats_get(dbname, colortype): results = {} database = Database(dbname) with database: _, colors, _ = _formatsexecfunc(database, colortype) for color in colors: results[color[0]] = color[1] return (results)
def __init__(self,dbname,tblname,fldname,**kwargs): database = Database(dbname) with database: rows = tbl_rows_get(database,tblname, [fldname]) # rows is a tuple; list is element 2 kwargs['set'] = [row[0] for row in rows[1]] super(DBSetMember,self).__init__(**kwargs) self.validations.append(_SetMemberVdt(**kwargs))
def setUp(self,dbname,refdbname): dbpath = '/Users/burtnolej/Development/pythonapps3/clean/apps/schoolschedulewizard/test_sswizard' chdir(dbpath) self.dbname = dbname self.dbfilename = path.join(dbpath,self.dbname) self.database = Database(self.dbfilename) self.of = ObjFactory(True) self.ui = WizardUI(self.dbname, self.of,refdbname) self.ui.dbname_entry_sv.set(dbname) parent_name = self.ui.entrygrid.widgets[0][0].winfo_parent() self.parent_widget = self.ui.entrygrid.widgets[0][0]._nametowidget(parent_name) self.parent_widget.update()
def setUp(self): #Test_Base.setUp(self) self.databasename = CURRENTDIR + "/" + THISEXEC + "/" + "quad" self.database = Database(self.databasename) try: with self.database: tbl_remove(self.database, 'lesson') tbl_remove(self.database, 'session') except: pass
def setUp(self): self.database = Database(CURRENTDIR + "/" + THISEXEC + "/" + 'test_sswizard') self.classtbl = 'class' self.maxx = 8 self.maxy = 10 widget_args = dict(background='white') self.widgetcfg = nxnarraycreate(self.maxx + 1, self.maxy + 1, widget_args) self.widgetcfg = dropdown_build(self.database, self.widgetcfg, _execfunc, 5, "MO", _rowheaderexecfunc, _columnheaderexecfunc)
def setUp(self): self.dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'test_ssviewer_rest_dump' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all", prep=-1, database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database, refdatabase=self.database, saveversion=1, of=self.of, enums=self.enums) ssviewer_utils.dataset_load(**args)
def setUp(self): dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'service_getrecord_1lesson' self.database = Database(dbname) self.of = ObjFactory(True) enums = sswizard_utils.setenums(dow="all", prep=-1, database=self.database) args = dict(database=self.database, refdatabase=self.database, saveversion=1, of=self.of, enums=enums) ssviewer_utils.dataset_load(**args)
def test_from_db(self): tcxparser = TcxParser(TEST_FILES,databasename="foo",tablename="foo2") limits = tcxparser.get_limits_from_db('bar') expected_results = {u'test_9trackpoints': {'start': 2, 'end': 6}, u'test_all_trackpoints': {'start': 900, 'end': 1500}} self.assertEqual(limits,expected_results) tcxparser.process_files(summation_type="avg",limits=limits,bucket_size=2) tcxparser.persist() database = Database('foo',True) with database: _,rows,_ = tbl_query(database,'select watts from foo2 where filename=\"test_9trackpoints\"') self.assertListEqual(rows,self.wattsavg_points)
def setUp(self): self.databasename = 'foo' self.database = Database(self.databasename) self.rawdata = [[1, 240, 'fileA'], [2, 241, 'fileA'], [3, 242, 'fileB'], [4, 240, 'fileB']] self.files = ['fileA', 'fileB'] self.col_defn = [("id", "integer"), ("watts", "integer"), ("filename", "string")] self.col_names = ["id", "watts", "filename"] self.tablename = "bar" _rows = _quotestrs(self.rawdata) with self.database: tbl_create(self.database, self.tablename, self.col_defn) tbl_rows_insert(self.database, self.tablename, self.col_names, _rows)
def test_(self): start = "10:01" end = "20:02" new_file_name = "foo" ride_title = "foo_title" workout_type = "z2" row = _quotestrs( [[start, end, new_file_name, ride_title, workout_type]]) self.dtr_tcx._write_to_db(row, self.dname, self.tname, self.cdefns, self.cnames) expected_results = [[u'10:01', u'20:02', u'foo', u'foo_title', u'z2']] database = Database(self.dname, True) with database: _, rows, _ = tbl_rows_get(database, self.tname) self.assertListEqual(expected_results, rows)
def delrow(self): database = Database(self.dbname_entry_sv.get()) for i in range(self.maxrows): if i <> 0: widget = self.entrygridxlabel.widgets[i][0] if widget['style'] == widget.style_on: pk_id = self.pk_entry_sv.get() pk_id_index = self.colnames.index(pk_id) pkval = self.entrygrid.widgets[i-1][pk_id_index].sv.get() with database: exec_str = tbl_row_delete(database,self.tblname_entry_sv.get(), [[pk_id,"=","\""+pkval+"\""]]) self.lastquery_text_sv.set(exec_str) self.clear() self.load()
def dropdowns_set(self): # make sure that the refdatabase is the same as the database self.refdatabase = Database(self.dbname_entry_sv.get()) #widget_args=dict(background='red',width=9,values=self.enums['student']) widget_args = dict(background='red', width=9, values=[]) widgetcfg = nxnarraycreate(self.maxrows, self.maxcols, widget_args) widgetcfg = sswizard_utils.dropdown_build(self.refdatabase, widgetcfg, _execfunc, self.prep_entry_sv.get(), self.dow_entry_sv.get(), _columnheaderexecfunc, _rowheaderexecfunc) for x in range(self.maxrows): for y in range(self.maxcols): _widget = self.entrygrid.widgets[x][y] _widget.config(**widgetcfg[x][y]) #setattr(_widget,"orig_values",_widget['values']) setattr(_widget, "orig_values", _widget['values'])
def get_limits_from_db(self, tablename): database = Database(self.databasename, testexists=True) with database: _, rows, _ = tbl_rows_get(database, tablename) self.limits = {} for _row in rows: start_hour = 0 end_hour = 0 new_file_name = _row[2] self.limits[new_file_name] = {} self.limits[new_file_name]['start'] = self.time_to_seconds(_row[0]) self.limits[new_file_name]['end'] = self.time_to_seconds(_row[1]) log.log(PRIORITY.SUCCESS, msg="limits retreived from database [" + self.databasename + "[ for files [" + ",".join(self.limits.keys()) + "]") return self.limits
def persist(self, f=None, column_defn=[("id", "integer"), ("bucket", "integer"), ("watts", "integer"), ("hr", "integer"), ("filename", "text")], column_names=["id", "bucket", "watts", "hr", "filename"]): database = Database(self.databasename) _rows = self.dump(f) with database: if tbl_exists(database, self.tablename) == False: tbl_create(database, self.tablename, column_defn) try: tbl_rows_insert(database, self.tablename, column_names, _rows) except Exception, e: log.log(PRIORITY.FAILURE, msg="timseries persistence failed in db [" + database.name + "] [" + e.message + "]") else:
def formats_db_load(dbname="test_ssloader"): tblname = "formats" hex2name = {} for key, value in colors.attr_get_keyval(include_callable=False, include_baseattr=False): hex2name[value] = key formats_col_defn = [('name', 'text'), ('fgcolor', 'text'), ('bgcolor', 'text'), ('__id', 'text'), ('__timestamp', 'text')] formats_col_names = [row[0] for row in formats_col_defn] dbrows = [] for name, bg in colorpalette.iteritems(): if fontpalette.has_key(name): fg = fontpalette[name] else: fg = '#000000' __id = IDGenerator().getid() __timestamp = datetime.now().strftime("%H:%M:%S") dbrows.append([ "\"" + name + "\"", "\"" + hex2name[fg] + "\"", "\"" + hex2name[bg] + "\"", "\"" + __id + "\"", "\"" + __timestamp + "\"" ]) database = Database(dbname) with database: if tbl_exists(database, tblname) == True: tbl_remove(database, tblname) tbl_create(database, tblname, formats_col_defn) exec_str, result = tbl_rows_insert(database, tblname, formats_col_names, dbrows)
def test_(self): self.dtr_tcx.load_page(self.baseurl) self.dtr_tcx.login(self.xpaths, self.uname, self.pword) self.xpaths[ 'rideListName'] = "//div[contains(@class,'ride-list-name')]" rides = self.dtr_tcx.get_rides(1) self.xpaths['downloadRide'] = "//a[contains(@class,'downloadRide')]" self.xpaths['rideListDate'] = "//p[contains(@class,'gray-light')]/span" self.xpaths['rideTitle'] = "//h1[contains(@class,'mb0')]/a" self.xpaths['notes'] = "//textarea[contains(@class,'form-control')]" self.dtr_tcx.download_rides(rides, self.xpaths) database = Database(self.dname, True) with database: _, rows, _ = tbl_rows_get(database, self.tname) self.assertTrue(len(rows), 1) self.assertTrue(len(rows[0]), 4) self.xpaths['rideListDate'] = "//p[contains(@class,'gray-light')]/span" self.xpaths['rideTitle'] = "//h1[contains(@class,'mb0')]/a" # get the file name that would have been downloaded # check it has been downloaded and then delete it self.dtr_tcx.mydriver.get(rides[0]) ride_file_name = self.dtr_tcx._get_ride_file_name( rides[0], self.xpaths) self.assertTrue(os_file_exists(DOWNLOAD_DIR + "\\" + ride_file_name)) os.remove(DOWNLOAD_DIR + "\\" + ride_file_name)
def setUp(self): self.databasename = 'foo' self.database = Database(self.databasename) self.rawdata = [[1, 1, 130, 240, 'fileA'], [2, 2, 131, 241, 'fileA'], [3, 3, 132, 242, 'fileA'], [4, 4, 133, 240, 'fileA'], [5, 5, 132, 261, 'fileA'], [6, 6, 131, 262, 'fileA'], [7, 1, 150, 310, 'fileB'], [8, 2, 152, 307, 'fileB'], [9, 3, 154, 309, 'fileB'], [10, 4, 152, 306, 'fileB'], [11, 5, 151, 310, 'fileB'], [12, 6, 157, 311, 'fileB']] self.files = ['fileA', 'fileB'] self.col_defn = [("id", "integer"), ("bucket", "integer"), ("hr", "integer"), ("watts", "integer"), ("filename", "string")] self.col_names = ["id", "bucket", "hr", "watts", "filename"] self.tablename = "bar" _rows = _quotestrs(self.rawdata) with self.database: tbl_create(self.database, self.tablename, self.col_defn) tbl_rows_insert(self.database, self.tablename, self.col_names, _rows)
def load(self,afterinsert=False,values=None): colwidths = [] if afterinsert==True: # we dont need to reload the headers as this an update of existing table self.clear(1) database = Database(self.dbname_entry_sv.get()) whereclauses = [] if self.pred1_entry_sv.get() <> "": whereclauses.append([self.pred1_entry_sv.get(), self.pred1_op_entry_sv.get(), self.predval1_entry_sv.get()]) log.log(thisfuncname(),9,msg="where clause specified",whereclauses=whereclauses) if self.pred2_entry_sv.get() <> "": whereclauses.append([self.pred2_entry_sv.get(), self.pred2_op_entry_sv.get(), self.predval2_entry_sv.get()]) log.log(thisfuncname(),9,msg="where clause specified",whereclauses=whereclauses) if self.pred3_entry_sv.get() <> "": whereclauses.append([self.pred3_entry_sv.get(), self.pred3_op_entry_sv.get(), self.predval3_entry_sv.get()]) log.log(thisfuncname(),9,msg="where clause specified",whereclauses=whereclauses) with database: colndefn,rows,exec_str = tbl_rows_get(database,self.tblname_entry_sv.get(),"*",whereclauses) self.lastquery_text_sv.set(exec_str) self.lastquery_rowcount_text_sv.set(str(len(rows))) log.log(thisfuncname(),3,func=tbl_rows_get,msg=str(len(rows))+"rows loaded",table=self.tblname_entry_sv.get()) for y in range(len(colndefn)): self.dbcol_defn.append(colndefn[y]) new_value = colndefn[y] print y self.entrygrid.widgets[0][y].sv.set(new_value) self.entrygrid.widgets[0][y].current_value = new_value self.newrowgrid.widgets[0][y].sv.set(new_value) self.newrowgrid.widgets[0][y].current_value = new_value # reset init_value for headers after we have loaded # so we can determine a new column from an updated column self.entrygrid.widgets[0][y].init_value = new_value self.newrowgrid.widgets[0][y].init_value = new_value print rows #for x in range(len(rows)): for x in range(self.maxrows-1): # 1 taken up for header for y in range(len(rows[x])): #try: new_value = rows[x][y] # current widget widget = self.entrygrid.widgets[x+1][y] # this is so the entry widgets can distinguish between # nothing loaded and a space loaded if new_value == "": new_value = "<SPACE>" # +1 to avoid the header row widget.sv.set(new_value) widget.current_value = new_value # and set the style back to not updated widget['style'] = 'OutOfFocus.Notchanged.TEntry' try: if len(str(new_value)) > colwidths[y]: colwidths[y]=len(str(new_value)) except IndexError: colwidths.append(len(str(new_value))) # after load store the column headers for easy lookup later self.colnames = colndefn for i in range(len(colwidths)): self.entrygrid.canvasframe.grid_columnconfigure(i,weight=colwidths[i],uniform="foo") self.newrowgrid.canvasframe.grid_columnconfigure(i,weight=colwidths[i],uniform="foo")
def process_updates(self,database=None): if database == None: database = Database(self.dbname_entry_sv.get()) pkcolnum = self.dbcol_defn.index(self.pk_entry_sv.get()) rows=[] if len(self.updates.keys()) == 0: log.log(thisfuncname(),3,"wierd","len(updates)=0") for key in self.updates.keys(): row=[] gridname,x,y = key.split(",") # newrowgrid updates processed by insert; at some point # add a flag to grid constructor as to whether or not it # needs to put updates on the update queue if gridname == "entrygrid": colname = self.entrygrid.widgets[0][int(y)].sv.get() new_value,version = self.updates[key] # ignore any updates that are initial version (version=1) if int(x)==0: init_value = getattr(self,gridname).widgets[0][int(y)].init_value current_value = getattr(self,gridname).widgets[0][int(y)].current_value #new_value = getattr(self,gridname).widgets[0][int(y)].sv.get() if new_value <> current_value: log.log(thisfuncname(),3,msg="update_required",y=y,x=x,colname=colname,key=key) if init_value == "": with database: try: tbl_col_add(database, self.tblname_entry_sv.get(), new_value) log.log(thisfuncname(),4,func=tbl_col_add,current_value=current_value,new_value=new_value) getattr(self,gridname).widgets[0][int(y)].version += 1 except Exception,e: log.log(thisfuncname(),1,func=tbl_col_add,error=str(e)) else: #try: with database: tbl_col_update(database, self.tblname_entry_sv.get(), current_value, new_value) log.log(thisfuncname(),4,func=tbl_col_update,current_value=current_value,new_value=new_value) #except Exception,e: #log.log(thisfuncname(),1,func=tbl_col_update,error=str(e)) getattr(self,gridname).widgets[0][int(y)].current_value = new_value else: log.log(thisfuncname(),3,msg="ignoring as values have not changed",current_value=current_value,new_value=new_value) else: pkval = self.entrygrid.widgets[int(x)][pkcolnum].sv.get() # ignore updates that are not different from init_value # could be changed and then changed back or could be just inital load if str(new_value) <> str(self.entrygrid.widgets[int(x)][int(y)].current_value): try: new_value = int(new_value) except: new_value = "\""+new_value+"\"" _row= [colname,new_value,self.pk_entry_sv.get(),"\""+pkval+"\""] rows.append(_row) log.log(thisfuncname(),3,msg="add to dbupdate queue",x=x,y=y,colname=colname,new_value=new_value,pkval=pkval) self.entrygrid.widgets[int(x)][int(y)].current_value = new_value self.entrygrid.widgets[int(x)][int(y)].version += 1
def __init__(self, dbname, of, refdbname, maxentrycols=3, maxentryrows=4, maxnewrowcols=3, maxnewrowrows=3): log.log(thisfuncname(), 3, msg="initialize", dbname=dbname, refdbname=refdbname) self.clipboard = [] self.clipboard_selection = -1 Tk.__init__(self) self.geometry("2000x500+0+0") self.refdatabase = Database(refdbname) #self.enums = sswizard_utils.setenums('All','5',self.refdatabase) self.dbname = dbname self.database = Database(self.dbname) self.of = of font = tkFont.Font(family="monospace", size=12) self.lastsaveversion = 0 style = Style() style.theme_use("default") bigfont = tkFont.Font(family="Helvetica", size=50) self.option_add("*TCombobox*Listbox*Font", bigfont) self.current_inputmode = "Normal" set_configs(style) # any children that change update this # key is the name and value is the new val # the name is likely to be the tkwidgetid.x,y self.updates = OrderedDict() self.maxrows = maxentryrows # rows in the grid self.maxcols = maxentrycols # cols in the grid maxwidgets = self.maxrows * self.maxcols wwidth = 48 # default button width with text of 3 chars wheight = 29 # default button height wmheight = wheight * self.maxrows # master height wmwidth = wwidth * self.maxcols # master width #geom = geometry_get(1000,1000,0,0) #self.geometry(geom) self.bind("<Prior>", self.focus_next_widget) # daygrids setmemberp = SetMemberPartial(name='x{mylist}', set=['Monday']) widget_args = dict(background='white', width=9, font=font, values=['Monday']) widgetcfg = nxnarraycreate(self.maxrows, self.maxcols, widget_args) # daygrid 1 self.dowentrygrid = TkImageLabelGrid(self, 'dowentrygrid', setmemberp, wmwidth, wmheight, 0, 0, 1, self.maxcols, True, {}, widgetcfg) self.dowentrygrid.grid(row=0, column=0, sticky=EW) # entrygrids setmemberp = SetMemberPartial(name='x{mylist}', set=[]) widget_args = dict(background='white', width=9, font=font, values=[]) widgetcfg = nxnarraycreate(self.maxrows, self.maxcols, widget_args) # entrygrid 1 setmemberp.widgettype = TkGridCombobox self.entrygrid = TkImageLabelGrid(self, 'entrygrid', setmemberp, wmwidth, wmheight, 0, 0, self.maxrows, self.maxcols, True, True, {}, widgetcfg) self.entrygrid['style'] = 'EntryGrid.TFrame' self.entrygrid.grid(row=1, column=0, sticky=NSEW) buttonpanel = Frame(self, style='ControlPanel.TFrame') buttonpanel.grid(row=2, column=0, sticky=NSEW, columnspan=2) self.save_button = Button(buttonpanel, command=self.save, text="save", name="svb") self.save_button.grid(row=0, column=0) self.save_button.focus_get() self.persist_button = Button(buttonpanel, command=self.persist_lesson, text="persist", name="pb") self.persist_button.grid(row=0, column=1) self.persist_button.focus_get() self.dbload_button = Button(buttonpanel, command=self.load, text="dbload", name="dbl") self.dbload_button.grid(row=0, column=2) self.dbload_button.focus_get() self.clear_button = Button(buttonpanel, command=self.clear, text="clear", name="clr") self.clear_button.grid(row=0, column=3) self.clear_button.focus_get() self.viewer_button = Button(buttonpanel, command=self.viewer, text="viewer", name="view") self.viewer_button.grid(row=0, column=4) self.viewer_button.focus_get() self.rebuilddropdown_button = Button(buttonpanel, command=self.dropdowns_set, text="ddown", name="ddown") self.rebuilddropdown_button.grid(row=0, column=5) self.rebuilddropdown_button.focus_get() controlpanel = Frame(self, style='ControlPanel.TFrame') controlpanel.grid(row=3, column=0, sticky=NSEW, columnspan=2) self.dbload_entry_label = Label(controlpanel, text="version") self.dbload_entry_label.grid(row=0, column=0) self.dbload_entry_label.focus_get() self.dbload_entry_sv = StringVar() self.dbload_entry = Entry(controlpanel, textvariable=self.dbload_entry_sv) self.dbload_entry.grid(row=0, column=1) self.dbload_entry.focus_get() self.dbname_entry_label = Label(controlpanel, text="dbname") self.dbname_entry_label.grid(row=0, column=2) self.dbname_entry_label.focus_get() self.dbname_entry_sv = StringVar() self.dbname_entry = Entry(controlpanel, textvariable=self.dbname_entry_sv) self.dbname_entry.grid(row=0, column=3) self.dbname_entry.focus_get() self.dbname_entry_sv.set(self.dbname) self.dow_entry_label = Label(controlpanel, text="dow", width=10) self.dow_entry_label.grid(row=0, column=4) self.dow_entry_label.focus_get() self.dow_entry_sv = StringVar() self.dow_entry = Entry(controlpanel, textvariable=self.dow_entry_sv, width=10) self.dow_entry.grid(row=0, column=5) self.dow_entry.focus_get() self.dow_entry_sv.set('MO') self.prep_label = Label(controlpanel, text="prep", width=10) self.prep_label.grid(row=0, column=6) self.prep_label.focus_get() self.prep_entry_sv = StringVar() self.prep_entry = Entry(controlpanel, textvariable=self.prep_entry_sv, width=10) self.prep_entry.grid(row=0, column=7) self.prep_entry.focus_get() self.prep_entry_sv.set(5) self.grid_rowconfigure(0, weight=1, uniform="foo") self.grid_rowconfigure(1, weight=10, uniform="foo") self.grid_rowconfigure(2, weight=1, uniform="foo") self.grid_rowconfigure(3, weight=1, uniform="foo") self.grid_columnconfigure(0, weight=1, uniform="foo")