class Conversion(Frame): ''' Script creation graphical user interface. Since this page was crowding the main in order to neat this is a better place for it ''' def __init__(self, master=None, **options): #if not master and options.get('parent'): # master = options['parent'] self.master = master Frame.__init__(self, master) self.im_gear = self.master.im_gear # inner class object container self.objt_c = [] def create_conversion_gui(self): # first header row row = Frame(self) TEXT1= "\nSelect the parameters to perform the conversion: " Label(row, text=TEXT1, anchor='w').pack(side='top', padx=2, pady=10) row.pack( side='top', fill='x', padx=5) bottom_hline_deco(self) # file section #======================= DEFAULTS ========================= ex_files=['./Examples/IONP/Original/SPIO_part-water-em.gro', './Examples/IONP/Original/SPIO_part.top', './Examples/IONP/Original/forcefield.itp', './Examples/IONP/Original/ffoplsaaSI_FE_WATnb.itp', './Examples/IONP/Original/ffoplsaaSI_FE_WATbon.itp' ] #ex_files=['conf.gro','topol.top','forcefield.itp','nb.itp','bon.itp'] _atomstyle_ = 'full' _radio_ = 1 data_cont = self.master._convert_['setup'] if data_cont <> []: ex_files = data_cont[:-2] _atomstyle_ = data_cont[-2] _radio_ = data_cont[-1] fi_txt=['Enter the gro file', 'Enter the top file', 'Enter the forcefield file', 'Enter the non bonded file', 'Enter the bonded file' ] for fi in range( len( ex_files)): self.objt_c.append( self.master.createfileentry( self, fi_txt[fi], ex_files[fi], ) ) bottom_hline_deco( self) bottom_hline_deco( self, self.atomstyle) self.objt_c[-1].set( _atomstyle_) self.sol_buffer = _radio_ bottom_hline_deco( self, self.build_solvation_section) self.objt_c[-1].set( _radio_) # Final Buttons self.build_finalbuttons() def build_solvation_section( self): row = Frame(self) self.radio_part( row, 'Solvation atoms', [' yes',' no']) self.solv_b = Button( row, image= self.im_gear, width = 25, height=23, command= self.config_solvation ) self.solv_b.pack( side='right', padx=0) row.pack( side='top', fill='x', pady=3) def radio_part(self, _s_row_, _text_, _desc_=[''], _vals_=[]): _f_labels = format_dec([_s_row_, _text_])#, _pack_=False) radio_var = IntVar() for d in range( len( _desc_)): label_rb = Radiobutton(_s_row_, width=0, text= _desc_[d] ,variable = radio_var , value= len( _desc_)-1-d ,command = self.solvastuff , anchor='w' ) label_rb.pack(side='left', padx=6) self.objt_c.append( radio_var) def solvastuff(self): '''If this point is reached, some button changed ''' _solvation_ = self.objt_c[-1].get() if self.sol_buffer <> _solvation_: self.sol_buffer = _solvation_ if _solvation_: self.solv_b.configure( state = 'normal') else: pop_wrg_1('You are choosing to not consider solvation.' ,' If some solvent molecules are in the' +' .gro file they will be ignored!', _i_=0) self.solv_b.configure( state = 'disabled') def atomstyle( self): ''' in this case just one, but could be modified to be generic, accepting <row>, <text> and <options>''' a_mainrow= Frame( self) row_fst = Frame( a_mainrow) #from self-ttk import Combobox TEXT2= 'Choose an atom style' format_dec([row_fst, TEXT2]) row_fsep = Frame(row_fst) atom_var = StringVar() atom_style_ddl = Drop_Down_List(row_fsep, textvariable = atom_var, #state="readonly" ) atom_style_ddl['values'] = ('full', 'charge', 'molecular', 'angle', 'bond','atomic') atom_style_ddl.bind("<Key>", lambda e: "break") # Magic atom_style_ddl.pack() self.objt_c.append( atom_var) row_fsep.pack(side='left', fill='x', pady=0) # row packing row_fst.pack(side='left', pady=0) a_mainrow.pack(side='top', fill='x', pady=3) def build_finalbuttons(self): Frame(self).pack(side="top", fill='x', pady=20) # Space _row_= self self.b1 = Button(_row_, text='Convert', command = self.getdata_and_convert) self.b1.pack( side = 'right', padx=30, pady=15) b2 = Button(_row_, text = 'Quit', command = self.quit) b2.pack( side = 'right', padx=10, pady=4) def getdata_and_convert(self): _solvatedinfo_ = self.master._convert_['solvation'] if ( self.objt_c[-1].get() and _solvatedinfo_ == []): pop_wrg_1( 'First perform the solvation configuration.' + ' You can do it pressing in solvation settings gears', _i_=0 ) self.solv_b.invoke() elif self.get_entriesvalues(): data_cont = self.master._convert_['setup'] config = data_cont[-2:]+[0] sim_data, flag_done_ = extract_gromacs_data(data_cont[:-2], _solvatedinfo_, config[1:]) if flag_done_: flag_done_ = write_lammps_data( sim_data, 'data.gro2lam', config ) if flag_done_: print_dec_g( 'Data file generated as "data.gro2lam"' ) self._convertdata_ = sim_data self._convertdata_['config'] = config # Returning the values self.master._convertdata_ = self._convertdata_ self.master.swapbody(2) else: pop_wrg_1('The setup needs some further improvements' +'to be runed. Please check your inputs') def get_entriesvalues(self): ''' --- app entry getter ---- mainly to obtain values beside check buttons''' e_values=[] _flag_ = True ent_rang = range(len(self.objt_c)) for ent in ent_rang:#[1:]: e_values.append(self.objt_c[ent].get()) if ent <= 4: _flag_ *= check_file(e_values[-1]) self.master._convert_['setup'] = e_values return _flag_ def createWidgets(self): self.create_conversion_gui() def config_solvation( self): title_txt = ' '*15+'Input Water name' instructions = 'Enter the atom tag letters of:' askfor = ['O in the non bonded file', 'H in the non bonded file', 'O in the .gro file', 'H in the .gro file', 'H - O partial charge' #'Na+ in the .gro file (if are present)', #'Cl- in the .gro file (if are present)' ] _solvatedinfo_ = self.master._convert_['solvation'] if _solvatedinfo_ == []: defaultanswer = ['opls_116','opls_117','OW','HW1, HW2','0.4238' #,'Na','Cl' ] else: defaultanswer = _solvatedinfo_ self.solv_b.config(bg = 'gray40', width = 45) #cyan') self.master._aux_ = [] pop = PromptPopUp(master = self.master, title = title_txt, briefing = instructions, entries_txt = askfor, entries_val = defaultanswer ) pop.wait_window() if self.master._aux_ <> [] and self.get_entriesvalues(): _app_aux_ = self.master._aux_ #============ Check inputs ================= _flag_ = 1 nb_Ox, nbHy, gro_Oxs, gro_Hys, pch= _app_aux_ _gro_f, _, _, _nbn_f, _, _, _= self.master._convert_['setup'] _flags = check_in_file( _nbn_f, nb_Ox, nbHy) print ([nb_Ox, nbHy]) list_aux = [Ox.strip(' ') for Ox in gro_Oxs.split(',')] list_aux += [Ox.strip(' ') for Ox in gro_Hys.split(',')] _flags += check_in_file( _gro_f, *list_aux) print (list_aux) try: x = float(pch) if -10<x<10: _flags += [1] partial_charges = 'Partial charges for H: {} and for O: {}' print partial_charges.format( x, x*-2) else: _flags += [0] except: _flags += [0] list_aux = [nb_Ox, nbHy] + list_aux for v in range(len(_flags)): err_txt = '' if not _flags[v] and v <> (len(_flags)-1): filename = _nbn_f if v>1: filename = _gro_f err_txt = 'Atom tag {} not found in {}' if '/' in filename: filename = filename.split('/')[-1] err_txt = err_txt.format( list_aux[v], filename) _flag_*=0 elif not _flags[v]: err_txt = 'Non valid partial charge {}'.format( pch) _flag_*=0 if err_txt<>'': pop_err_1(err_txt+'\nSetup not saved') #============ Done! ================= if _flag_: self.master._convert_['solvation'] = _app_aux_ print_dec_g('Solvation setup saved!') #self.solv_b.focus() self.solv_b.config(bg = 'lightgrey', width = 28)
class Script_GUI(Frame): ''' Script creation graphical user interface. Since this page was crowding the main in order to neat this is a better place for it ''' def __init__(self, master=None, **options): #if not master and options.get('parent'): # master = options['parent'] self.master = master Frame.__init__(self, master) # Just as an extension self._convertdata_ = self.master._convertdata_ self.img = self.master.img self._container_ = self.master._script_ def createWidgets(self): 'create the script gui' # first header row row = Frame(self) TEXT1= "\nIn this section you can create input Lammps scripts " Label(row, text=TEXT1, anchor='w').pack(side='top', padx=2, pady=1) row.pack( side='top', fill='x', padx=5) bottom_hline_deco(self) bottom_hline_deco(self, self.create_main_section) self.build_finalbuttons() if self.master.test: self.after(2000, self.test_hook) def createWidgets_n_pack(self): self.createWidgets() self.pack() def create_main_section(self): '''Section for main input values ''' #===================================================================== ''' Create script section ''' row2fill = Frame(self) row2fill_l = Frame(row2fill) self.s_entry_c = [] _mainpage_ = self._container_['mainpage'] _defvals_ = [ '0.1', '1000', '1000', '300:299', '100', '1000','10:1', '1000', '299:300', '100'] _def_dataname_ = './data.gro2lam' if self._convertdata_ <> None: _def_dataname_ = self._convertdata_['filename'] elif _mainpage_ <> []: _def_dataname_ = _mainpage_[0] _defvals_ = _mainpage_[1:] self.s_entry_c.append( createfileentry( self, 'Lammps data file to work', _def_dataname_, ['.data', 'data.*'], ['lammps data', 'lammps data'], (self._convertdata_ == None) ) ) _entries_= [ 'Timestep [fs]', '-','NVE steps [#ts]','-', 'NVT steps [#ts]','Temperature at start:end [K]', 'Temperature damping [fs]', '-','NPT steps [#ts]', 'Pressure at start:end [atm]', 'Pressure damping [fs]', 'Temperature at start:end [K]', 'Temperature damping [fs]' ] entr_maxlen = int(len(max(_entries_, key=len))*2.5/3) c=0 for e in range(len(_entries_)): if _entries_[e]=='-': bottom_hline_deco(row2fill_l) c+=1 else: self.s_entry_c.append(create_entry(row2fill_l, _entries_[e], _defvals_[e-c], entr_maxlen)) row2fill_l.pack( side="left") # ==================== row2fill.pack(side="top", padx=1, pady=5) def build_finalbuttons(self): ''' Final Buttons ''' row = Frame(self) ######## ADVANCED OPTIONS ################# if self._container_['advanced'] == []: # advanced _init_ _pair_style_ = 'lj/cut/coul/cut' _comb_rl_ = 'No' lj_12_13_14_ = '0.0:0.0:0.0' co_12_13_14_ = '0.0:0.0:0.0' if self._convertdata_ <> None: _aux_here_ = self._convertdata_['defaults'] buckorlj, comb_rule, _flg_, f14_LJ, f14_Co = _aux_here_ if int( buckorlj) == 2: _pair_style_ = 'buck/coul/long' mix_val = {'1':'geometric', '2':'arithmetic', '3':'geometric'} _comb_rl_ = mix_val[comb_rule] if _flg_ == 'yes': lj_12_13_14_ = '0.0:0.0:'+f14_LJ co_12_13_14_ = '0.0:0.0:'+f14_Co self._container_['advanced'] = [[],[]] self._container_['advanced'][0] = [ '10', 'array', _pair_style_, '8.5','10','1.9', 'pppm', '1e-4', lj_12_13_14_, co_12_13_14_, '1','1', 'aniso', _comb_rl_, '300', '1e-10', 'NVE-NVT-NPT-NVT-R', '0.0001','0','0' ] self.fcb = Button( row, text = 'Advanced settings', compound='left', image = self.img['gear'], bg='gray86', height = 15, width = 145, command = self.further_config_script ) self.fcb.pack(side='left', padx=10, pady=0) ###### RESTRAIN GROUP ############## self.resb = Button( row, text = 'Restrain', command = self.config_restrain ) self.resb.pack(side='left', padx=10, pady=0) self.b1 = Button( row, text='Create',# height=8, command= self.write_script ) self.b1.pack(side='right', padx=2, pady=4) b2 = Button(row, text='Quit', command=self.quit) b2.pack(side='right', padx=20, pady=4) row.pack( side='top', fill='both', padx=5) def write_script(self): print 'Writing the lammps script' _mainpage_ = get_entriesvalue( self.s_entry_c) _flag_ = True # data ok flag _entries_ = [ 'float', 'int', 'int', 'float:', 'float', 'int', 'float:', 'float', 'float:', 'float'] _flag_ *= self.check_datafile( bool) _flag_ *= min( check_vars( _mainpage_[1:], _entries_)) if _flag_: self._container_['mainpage'] = _mainpage_ _script_setup_ = [ _mainpage_, self._container_['advanced'][0] , self._container_['restrain']] self.master._script_ = self._container_ _flag_ = write_lammps_input( _script_setup_, self._convertdata_) if _flag_: print_dec_g( 'Lammps script done!') self.master.swapbody(3) def further_config_script( self ): ''' Section for advaced settings ''' pop_wrg_1('Advanced settings!\nChanging these parameters could result' +' in a different simulation than the base one') defvals = [] title_txt = ' '*3+'+ Simulation Parameters' instructions = 'Input further simulation parameters' askfor = ['Thermo output every [#ts]', 'Atom mapping', 'Pairwise interactions', "L-J/Buck rcutoff ["+u'\u00c5'+"]", "Coulomb rcutoff ["+u'\u00c5'+"]", "Neighbor skin distance ["+u'\u00c5'+"]", 'Long-range solver', 'Long-range relative error', 'L-J interaction 1-2:1-3:1-4', 'Coul interaction 1-2:1-3:1-4', 'Neighbor delay [#ts]', 'Neighbor update [#ts]', 'Pressure control', 'Force mixing rule', 'Velocity creation Temp [K]', 'Energy minimization tolerance', 'Simulation order', '---', 'Shake tolerance', 'Shake bonds [b#]', 'Shake angles [a#]', ] _pair_style_ = ['lj/cut/coul/long','lj/cut/coul/cut', 'lj/cut', 'lj/charmm/coul/long', 'buck/coul/long', 'buck', 'buck/coul/cut', #'lj/cut/tip4p/cut', 'lj/cut/tip4p/long', #'lj/gromacs', 'lj/gromacs/coul/gromacs', #, 'none', 'zero'] if self._convertdata_ <> None: buckorlj = int( self._convertdata_['defaults'][0]) if buckorlj == 1: _pair_style_ = _pair_style_[ :3] + [_pair_style_[ -1]] else: _pair_style_ = _pair_style_[ 3:] _kspace_ = ['pppm', 'pppm/cg', 'ewald', 'pppm/disp', 'ewald/disp', #'pppm/tip4p', 'pppm/disp/tip4p' ] _comb_rule_ = ['No','geometric', 'arithmetic', 'sixthpower'] # ['advanced'][1] in case of drop down lists, to show the other cases self._container_['advanced'][1] = [ '', ['array', 'hash'], _pair_style_, '','','', _kspace_, '', '', '', '', '', ['aniso', 'iso', 'tri'], _comb_rule_, '','','', '', '', '' ] _defvals_ = [] for _ad_ in range(len(self._container_['advanced'][0])): if self._container_['advanced'][1][_ad_] <> '': _def_ = self._container_['advanced'][0][_ad_] _dfli_ = self._container_['advanced'][1][_ad_] _defvals_.append([ _def_, _dfli_]) else: _defvals_.append(self._container_['advanced'][0][_ad_]) self.fcb.config(bg = 'gray70')#, width = 155) #cyan') self.master._aux_ = [] pop = PromptPopUp(master = self.master, title = title_txt, briefing = instructions, entries_txt = askfor, entries_val = _defvals_ , width = 400, height = 665 ) pop.wait_window() _, bnty_len, anty_len = self.check_datafile() print bnty_len, anty_len if self.master._aux_ <> []: _advanced_ = self.master._aux_ _entries_ = [ 'int', '', '', 'float', 'float', 'float', '', 'float', ['<float::<', 0.0, 1.0],['<float::<', 0.0, 1.0], 'int', 'int', '', '', 'float', 'float',[list, '-','NVE','NVT','NPT','R','M'] ,'float', ['<int-x-int<:0', 1, bnty_len], ['<int-x-int<:0', 1, anty_len] ] _flag_ = min( check_vars( _advanced_, _entries_, 'Advanced settings not saved!')) if _flag_: self._container_['advanced'][0] = _advanced_ print_dec_g('Advanced settings saved') self.fcb.config(bg = 'gray86')#, width = 145) def config_restrain( self ): title_txt = ' '*28+'+ Restrain Goups' instructions = 'Select the group to restrain' #============ grouping ================ max_index, _, _ = self.check_datafile() if max_index: _defvals_ = self._container_['restrain'] if _defvals_ == []: g_names = ['all_group'] d_ids = ['{}:{}'.format( 1, max_index)] kxyz_c = ['1:xyz'] rest_ens = ['1-2'] #restrained_ensembles ck_init = [0] second_c = None if self._convertdata_<> None: _mol_niifi_ = self._convertdata_['atomsdata'][1] for mt in range(len( _mol_niifi_)): g_names.append(_mol_niifi_[mt][0]) d_ids.append('{}:{}'.format(*_mol_niifi_[mt][1:])) kxyz_c += ['1:xyz'] rest_ens += ['1-2'] ck_init += [0] else: g_names, d_ids, kxyz_c, rest_ens, ck_init = _defvals_[0] #print g_names,'\n', d_ids,'\n', kxyz_c,'\n', ck_init if _defvals_[1]<> None: second_c = _defvals_[1] else: second_c = None self.resb.config(bg = 'gray70')#, width = 45) #cyan') self.master._aux_ = [] pop = PromptPopUp_wck(master = self.master, title = title_txt, briefing = instructions, entries_txt = g_names, entries_val = kxyz_c, width = 530, #height = 365, range_id = d_ids, res_ens = rest_ens, chck_init = ck_init, extra_but = second_c, ) pop.wait_window() if self.master._aux_ <> []: sim_len = 0 for x in self._container_['advanced'][0][-4].split('-'): if x.strip(' ') <> 'R': sim_len +=1 _res_flag_= [[],[]] _restrain_ = self.master._aux_[:] _, _d_ids, _kxyz_c, _runs_c, _res_flag_[0] = _restrain_[0] if _restrain_[1] <> None: _, au2, au3, au4, au5 = _restrain_[1][:] _restrain_aux = _d_ids+ au2+ _kxyz_c+ au3+ _runs_c+ au4 _res_flag_[1] = au5 else: _restrain_aux = _d_ids+ _kxyz_c+ _runs_c _multi_ = len(_restrain_aux)/3 _entries_ = ([['<int:int<', 1, max_index]]*_multi_ + ['float:xyz']*_multi_ + [['<int-x-int<:0', 1, sim_len]]*_multi_) _aux_ = check_vars( _restrain_aux, _entries_, 'Restrain groups not saved!') #print _aux_ _flag_ = min( _aux_) if _flag_: if max(max(_res_flag_)): self._container_['restrain'] = _restrain_ print_dec_g('Restrain data saved') else: print ('Creating 0 groups, Restraining 0 atoms') self.resb.config(bg = 'gray86')#, width = 45) def check_datafile(self, _bflag_=None): ''' function to get the max atom number also is used in case of no gromacs direct data conversion to somehow make a check if that file is ok ''' max_at_index, bond_types, angle_types = 0, 0, 0 _flag_ = True if self._convertdata_<> None: _numbers_ = self._convertdata_['numbers'] max_at_index = _numbers_['total'][0] _, bond_types, angle_types, _, _ = _numbers_['type'] else: _filename_ = self.s_entry_c[0].get() try: with open(_filename_, 'r') as indata: for k_line in indata: if not k_line.startswith('#'): line_c = k_line.split() if 'atoms' in line_c: max_at_index = line_c[0] if 'types' in line_c: if 'bond' in line_c: bond_types = line_c[0] elif 'angle' in line_c: angle_types = line_c[0] break except IOError: pop_wrg_1('Data file not found!') print ('Try performing a conversion first!') _flag_ = False if _bflag_<>None: return _flag_ return max_at_index, bond_types, angle_types def test_hook(self, event=None): self.b1.invoke()
#!/usr/bin/python import os from Tkinter import Tk, Label, Button, Entry, ACTIVE root = Tk() root.wm_title("Enter MFA Token") Label(root, text="Token").pack() entry = Entry(root) entry.pack(padx=5) def done(): print entry.get() root.destroy() b = Button(root, text="OK", default=ACTIVE, command=done) b.pack(pady=5) entry.focus_force() root.bind('<Return>', (lambda e, b=b: b.invoke())) os.system(('''/usr/bin/osascript -e 'tell app "Finder" to set ''' '''frontmost of process "Python" to true' ''')) root.mainloop()
class Conversion(Frame): ''' Script creation graphical user interface. Since this page was crowding the main in order to neat this is a better place for it ''' def __init__(self, master=None, **kwargs): #if not master and options.get('parent'): # master = options['parent'] self.master = master Frame.__init__(self, master) self.img = self.master.img # inner class object container self.objt_c = [] self.file_e = [] def create_conversion_gui(self): # file section #======================= DEFAULTS ========================= _autoload_ = 0 eg_files = [ './Examples/IONP/gromacs/SPIO_em.gro', './Examples/IONP/gromacs/SPIO_part.top', './Examples/IONP/gromacs/forcefield.itp', './Examples/IONP/gromacs/ffoplsaaSI_FE_WATnb.itp', './Examples/IONP/gromacs/ffoplsaaSI_FE_WATbon.itp' ] #eg_files=['conf.gro','topol.top','forcefield.itp','nb.itp','bon.itp'] _atomstyle_ = 'full' data_cont = self.master._convert_['setup'] if data_cont <> []: _autoload_ = data_cont[0] eg_files = data_cont[1:-1] _atomstyle_ = data_cont[-1] if _autoload_: enabled = [1, 1, 0, 0, 0] else: enabled = [1, 1, 1, 1, 1] fi_txt = [ 'Enter the gro file', 'Enter the top file', 'Enter the forcefield file', 'Enter the non bonded file', 'Enter the bonded file' ] ###### CONSTRUCTION SITE ############### ## CS first header row row = Frame(self) TEXT1 = "\nSelect the parameters to perform the conversion: " Label(row, text=TEXT1, anchor='w').pack(side='top', padx=2, pady=10) row.pack(side='top', fill='x', padx=5) bottom_hline_deco(self) ## CS files ------------------------- :@ # appends file entries capturing button also self.objt_c.append(_autoload_) # allocating space for autoload in [0] for fi in range(len(eg_files)): self.file_e.append( File_Entry(self, e_txt=fi_txt[fi], e_val=eg_files[fi])) self.file_e[-1].setter(enabled[fi]) self.objt_c.append(self.file_e[-1]._entry) self.file_e[-1].pack(fill='x') if fi == 1: self.file_e[-1]._strvar.trace('w', self.load_top_file) #sv = self.file_e[-1]._strvar #sv.trace('w', lambda name, index, mode, sv=sv: self.load_top_file(sv) ) #"w" bottom_hline_deco(self) ## CS autoload ------------------------- :@ # self.objt_c.append inside self.autoload_buffer = '' self.autoloadff() bottom_hline_deco(self) ## CS atom style ------------------------- :@ # self.objt_c.append inside bottom_hline_deco(self, self.atomstyle) self.objt_c[-1].set(_atomstyle_) # Final Buttons ------------------------- :@ self.build_finalbuttons() ###### END CONSTRUCTION SITE -> PACK OUTSIDE ######### if self.master.test: print 'Seeing main gro2lam converter GUI' self.after(2000, self.test_hook) def atomstyle(self): ''' in this case just one, but could be modified to be generic, accepting <row>, <text> and <options>''' a_mainrow = Frame(self) row_fst = Frame(a_mainrow) #from self-ttk import Combobox TEXT2 = 'Choose an atom style' format_dec([row_fst, TEXT2]) row_fsep = Frame(row_fst) atom_var = StringVar() atom_style_ddl = Drop_Down_List( row_fsep, textvariable=atom_var, #state="readonly" ) atom_style_ddl['values'] = ('full', 'charge', 'molecular', 'angle', 'bond', 'atomic') atom_style_ddl.bind("<Key>", lambda e: "break") # Magic atom_style_ddl.pack() self.objt_c.append(atom_var) row_fsep.pack(side='left', fill='x', pady=0) # row packing row_fst.pack(side='left', pady=0) a_mainrow.pack(side='top', fill='x', pady=3) def autoloadff(self): ''' function that enables the autoload of the forcefield files as stated in the top file, also as a logic side effect disables the file load option for forcefields ''' _a_row_ = Frame(self) _text_ = 'Autoload forcefield files' bt_txt_ = 'Press to autoload' _f_labels = format_dec([_a_row_, _text_]) self.autol_b = Button( _a_row_, text=bt_txt_, #width = 25, height=23, command=self.autoloadstuff) self.autol_b.pack(padx=0) #side='center', _a_row_.pack(side='top', fill='x', pady=3) def autoloadstuff(self): nonerr_flag = True #_autoload_ = self.objt_c[0].get() main_top_file = self.objt_c[2].get() if self.autoload_buffer <> main_top_file: # self.autoload_buffer = _autoload_ self.autoload_buffer = main_top_file aux_cont, nonerr_flag = get_ffldfiles(main_top_file) if nonerr_flag: for i in [2, 3, 4]: nonerr_flag *= check_file(aux_cont[i - 2]) self.file_e[i]._entry.delete(0, 'end') self.file_e[i]._entry.insert(0, aux_cont[i - 2]) self.file_e[i]._entry.xview_moveto(1) self.file_e[i].setter(0) self.objt_c[0] = (1) else: self.objt_c[0] = (0) elif self.objt_c[0] and self.autoload_buffer == main_top_file: pop_wrg_1('Autoload already performed for selected top file.', _i_=0) if not self.objt_c[0]: pop_err_1('Autoload failed!') self.autoload_buffer = '' self.autol_b.configure(state='disabled') for i in [2, 3, 4]: self.file_e[i].setter(1) def load_top_file(self, *args): #event=None, ''' function to capture the change in the top load button. in order to avoid the the waving experienced with a first "''" in the entry an if is inside ''' #print args if self.objt_c[2].get() <> '': #print ( self.objt_c[2].get()) self.autol_b.configure(state='normal') for i in [2, 3, 4]: self.file_e[i].setter(1) def build_finalbuttons(self): _ypadhere_ = 1 Frame(self).pack(side="top", fill='x', pady=35) # Space _row_ = self self.b1 = Button(_row_, text='Convert', command=self.getdata_and_convert) self.b1.pack(side='right', padx=30, pady=_ypadhere_) b2 = Button(_row_, text='Quit', command=self.quit) b2.pack(side='right', padx=10, pady=_ypadhere_) def getdata_and_convert(self): _autoload_ = self.objt_c[0] if not _autoload_: pop_wrg_1('Proceeding without autoload.\nThis means that any ' + 'internal address to files that are not specified ' + 'as GUI input are going to be ignored.') if self.get_entriesvalues(): data_cont = self.master._convert_['setup'] root_folder = '/'.join(data_cont[1].split('/')[:-1] + ['']) print('Root folder: {}'.format(root_folder)) sim_data, _flags_ = extract_gromacs_data(data_cont[1:-1], _autoload_) flag_done_, _sidemol_ = _flags_ config = [data_cont[-1], _sidemol_, _autoload_, root_folder] if flag_done_: try: flag_done_, data_fnam = write_lammps_data( sim_data, 'data.gro2lam', config) except KeyError as Err: err_str = '' for er in Err.args: err_str += er + ' ' pop_err_1( 'There are missing or incomplete coefficients in' + ' your input files related to: ' + err_str) flag_done_ = False except Exception as Exc: pop_err_1( 'There are inconsistencies in your input files\n' + Exc.args[0]) flag_done_ = False if flag_done_: print_dec_g('Data file generated as "data.gro2lam"') self._convertdata_ = sim_data self._convertdata_['filename'] = data_fnam self._convertdata_['config'] = config # Returning the values self.master._convertdata_ = self._convertdata_ # to ensure freshness of our dependant values self.master._script_['advanced'] = [] self.master._script_['restrain'] = [] self.master.swapbody(2) else: pop_wrg_1('The setup needs some further improvements' + 'to be runed. Please check your inputs') def get_entriesvalues(self): ''' --- app entry getter ---- mainly to obtain values beside check buttons ... which check buttons? ''' e_values = [] _flag_ = True ent_rang = range(len(self.objt_c)) for ent in ent_rang: #[1:]: if ent == 0: e_values.append(self.objt_c[ent]) else: e_values.append(self.objt_c[ent].get()) if ent and ent <= 5: _flag_ *= check_file(e_values[-1]) self.master._convert_['setup'] = e_values return _flag_ def test_hook(self, event=None): self.autol_b.invoke() self.b1.invoke() def createWidgets(self): ''' unified name hook''' self.create_conversion_gui()
class App: def __init__(self, master): self.master = master self.btnUpPressed = False self.btnDownPressed = False self.btnLeftPressed = False self.btnRightPressed = False self.btnPlusPressed = False self.btnMinusPressed = False #keyListener aanzetten master.bind("<Key>", self.keyPressed) master.bind("<KeyRelease>", self.keyReleased) labelFont = tkFont.Font(size = 16) #TOPFRAME: 800x400 topFrame = Frame(master, width=800,height=400, bg = "blue") topFrame.pack(padx=10, pady=10, side = TOP) leftTopFrame = Frame(topFrame, bg = "blue") leftTopFrame.grid(row = 0, column = 0) rightTopFrame = Frame(topFrame, bg = "blue") rightTopFrame.grid(row = 0, column = 2) middleTopFrame = Frame(topFrame, bg = "blue") middleTopFrame.grid(row = 0, column = 1, padx = 10) #BOTTOMFRAME: 800X200 bottomFrame = Frame(master, width=800,height=200, bg = "blue") bottomFrame.pack(padx=20, pady=10, side = BOTTOM) leftBottomFrame = Frame(bottomFrame, bg = "blue") leftBottomFrame.pack(side = LEFT) rightBottomFrame = Frame(bottomFrame, bg = "blue") rightBottomFrame.pack(side = RIGHT) leftRightBottomFrame = Frame(rightBottomFrame, bg = "blue") leftRightBottomFrame.pack(padx = 30, side = LEFT) rightRightBottomFrame = Frame(rightBottomFrame, bg = "blue") rightRightBottomFrame.pack(side = RIGHT) """ topFrame decoreren """ #Scrolledtext in leftTopFrame self.scrDebug = ScrolledText(leftTopFrame, wrap = WORD, state = "disabled", fg = "green", width=65) self.scrDebug.pack(fill=NONE, expand=False) #Tekst in rightTopFrame self.lblLaatstGenomen = Label(rightTopFrame, text="Laatst genomen foto:", bg = "gray55", fg = "white") self.lblLaatstGenomen.pack() #Image in rightTopFrame self.location = "../latestPicture.gif" self.laatstGenomen = PhotoImage(file="../default.gif") self.lblFotoLaatstGenomen = Label(rightTopFrame, image=self.laatstGenomen) #self.lblFotoLaatstGenomen.image = self.laatstGenomen self.lblFotoLaatstGenomen.pack(fill = BOTH, expand = "yes") #Vertaling in rightTopFrame self.vertalingString = StringVar() self.vertalingString.set("Vertaling QR-code: ") self.lblVertaling = Label(rightTopFrame, textvariable = self.vertalingString, bg = "gray55", fg = "white") self.lblVertaling.pack() self.btnMaakFoto = Button(rightTopFrame, text = "Maak Foto", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", width = 14, command = self.makePicture) self.btnMaakFoto.pack() #motor info in middleTopFrame self.lblmotorUpString = Label(middleTopFrame, text = "MOTOR U: " , bg = "blue", fg = "red", font = labelFont) self.lblmotorUpString.grid(row = 0, column = 0) self.lblmotorLeftString = Label(middleTopFrame, text = "MOTOR L: " , bg = "blue", fg = "red", font = labelFont) self.lblmotorLeftString.grid(row = 1, column = 0) self.lblmotorRightString = Label(middleTopFrame, text = "MOTOR R: " , bg = "blue", fg = "red", font = labelFont) self.lblmotorRightString.grid(row = 2, column = 0) self.lblmotorPWMString = Label(middleTopFrame, text = "PWM U: " , bg = "blue", fg = "white", font = labelFont) self.lblmotorPWMString.grid(row = 3, column = 0) self.motorLeftString = StringVar() self.motorLeftString.set("S") self.motorRightString = StringVar() self.motorRightString.set("S") self.motorUpString = StringVar() self.motorUpString.set("S") self.motorPWMString = StringVar() self.motorPWMString.set("100") self.lblmotorUpStringValue = Label(middleTopFrame, textvariable = self.motorUpString, fg = "red", bg = "blue", width = 5, font = labelFont) self.lblmotorUpStringValue.grid(row = 0, column = 1) self.lblmotorLeftStringValue = Label(middleTopFrame, textvariable = self.motorLeftString, fg = "red", bg = "blue", width = 5, font = labelFont) self.lblmotorLeftStringValue.grid(row = 1, column = 1) self.lblmotorRightStringValue = Label(middleTopFrame, textvariable = self.motorRightString, fg = "red", bg = "blue", width = 5, font = labelFont) self.lblmotorRightStringValue.grid(row = 2, column = 1) self.motorPWMStringValue = Label(middleTopFrame, textvariable = self.motorPWMString, fg = "white", bg = "blue", width = 5, font = labelFont) self.motorPWMStringValue.grid(row = 3, column = 1) """ bottomFrame decoreren to do: enum """ #Besturingsknoppen draaien in leftBottomFrame self.btnLeft = Button(leftBottomFrame, text="Links", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", height=3, width=10, command = lambda: self.moveLeft()) self.btnLeft.grid(row=1, column=0) self.btnRight = Button(leftBottomFrame, text="Rechts", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", height=3, width=10, command = lambda: self.moveRight()) self.btnRight.grid(row=1, column=2) self.btnForward = Button(leftBottomFrame, text="Vooruit", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", height=3, width=10, command = lambda: self.moveForward()) self.btnForward.grid(row=0, column=1) self.btnBackward = Button(leftBottomFrame, text="Achteruit", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", height=3, width=10, command = lambda: self.moveBackward()) self.btnBackward.grid(row=1, column=1) #Besturingsknoppen stijgen en dalen in middleBottomFrame self.btnUp = Button(leftRightBottomFrame, text="Omhoog", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", height=3, width=10, command = lambda: self.moveUp()) self.btnUp.grid(row=0, column=0) self.btnDown = Button(leftRightBottomFrame, text="Omlaag", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", height=3, width=10, command = lambda: self.moveDown()) self.btnDown.grid(row=1, column=0) self.lastCommandoString = "" #Hoogte informatie in RightBottomFrame self.gewensteHoogteString = StringVar() self.gewensteHoogteString.set(str(neededHeight)) self.lblGewensteHoogte = Label(rightRightBottomFrame, text = "Gewenste Hoogte: ", anchor = "w", bg = "gray55", fg = "white") self.lblGewensteHoogteVar = Label(rightRightBottomFrame, textvariable = self.gewensteHoogteString, width = 20, fg = "green") self.gemetenHoogteString = StringVar() self.gemetenHoogteString.set(str(realHeight)) self.lblGemetenHoogte = Label(rightRightBottomFrame, text="Gemeten Hoogte: ", anchor = "w", bg = "gray55", fg = "white") self.lblGemetenHoogteVar = Label(rightRightBottomFrame, textvariable = self.gemetenHoogteString, width = 20, fg = "green") self.lblGewensteHoogte.grid(row=1, column=0) self.lblGewensteHoogteVar.grid(row=1, column=1) self.lblGemetenHoogte.grid(row=0, column=0) self.lblGemetenHoogteVar.grid(row=0, column=1) self.btnHeight = Button(rightRightBottomFrame, text="Kies hoogte", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", width = 14, command = lambda: self.setGewensteHoogte()) self.btnHeight.grid(row=2,column=0) self.txtHeight = Entry(rightRightBottomFrame, width=24, fg = "green") self.txtHeight.grid(row=2, column=1) self.txtHeight.bind('<Return>', self.setGewensteHoogte) self.btnPWM = Button(rightRightBottomFrame, text="Kies PWM", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", width = 14, command = lambda: self.setPWM()) self.btnPWM.grid(row=2,column=2) self.txtPWM = Entry(rightRightBottomFrame, width = 24, fg = "green") self.txtPWM.grid(row=2, column = 3) self.txtPWM.bind('<Return>', self.setPWM) self.btnLand = Button(rightRightBottomFrame, text = "Landen", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", width = 14, command = self.landen) self.btnLand.grid(pady=5,row=3, column = 0) self.btnHorizontalOff = Button(rightRightBottomFrame, text = "Horizontale motors af", bg = "green", fg = "white", activebackground = "orange red", activeforeground = "white", command = self.horizontalOff) self.btnHorizontalOff.grid(pady=5,row=3, column = 1) self.correctieFlag = False self.automaticFlag = False self.btnAutomaticPilot = Button(rightRightBottomFrame, text = "Auto-pilot", bg = "green", fg = "white",activebackground = "orange red", activeforeground = "white", width = 14, command = lambda: self.toggleAutomaticPilot()) self.btnAutomaticPilot.grid(row = 0, column = 2) self.btnCorrectie = Button(rightRightBottomFrame, text ="Hoogte correctie", bg ="green", fg ="white", activebackground = "orange red", activeforeground = "white", width = 14, command = lambda: self.toggleHeightCorrection()) self.btnCorrectie.grid(row = 1, column = 2) self.btnConnect = Button(rightRightBottomFrame, text = "Verbind", bg = "green", fg = "white", activebackground = "orange red", width = 14, activeforeground = "white", command = lambda: self.createClient()) self.btnConnect.grid(row = 3, column = 2) self.connectedString = StringVar() self.connectedString.set("Niet verbonden") self.lblConnected = Label(rightRightBottomFrame, textvariable = self.connectedString, fg = "red", bg = "blue", font = tkFont.Font(size = 14)) self.lblConnected.grid(row = 3, column = 3) self.createClient() #gewenste hoogte aanpassen def setGewensteHoogte(self, event = None): x = self.txtHeight.get() self.txtHeight.delete(0, END) self.master.focus() try: x = float(x) except: return if isinstance(x, float) and x > 0.0 and x < 1000.0: global neededHeight neededHeight = x message = "Hoogte instellen op " + str(neededHeight) + " aangevraagd" self.debugPrint(message) self.gewensteHoogteString.set(str(neededHeight)) self.client.setHeight(x) if not self.correctieFlag: self.toggleHeightCorrection() def toggleAutomaticPilot(self): if not self.connected: return self.debugPrint("Automatische piloot toggle aangevraagd") self.client.toggleAutomaticPilot() def createClient(self): try: self.client = cl(self) self.connected = True self.connectedString.set("Verbonden") self.lblConnected.config(fg = "green") self.debugPrint("Verbonden met Raspberry Pi") except: self.debugPrint("Verbinding met Rapsberry Pi niet mogelijk:\n -Staat de Raspberry Pi aan?\n -Staat de server aan?\n -Zit deze computer op de ad-hoc?") def disconnect(self): self.connected = False self.connectedString.set("Niet verbonden") self.lblConnected.config(fg = "red") #PWM aanpassen def setPWM(self, event = None): x = self.txtPWM.get() self.txtPWM.delete(0, END) self.master.focus() try: x = int(x) except: return try: if not self.connected: return message = "PWM instellen op " + str(x) + " aangevraagd" self.debugPrint(message) self.client.setPower(x) except TypeError: return #automatische hooogte correctie toggelen def toggleHeightCorrection(self): if not self.connected or self.automaticFlag: return self.debugPrint("Automatische hoogte regeling toggle aangevraagd") self.client.toggleHeightCorrection() # #make picture # def makePicture(self): # if not self.connected: # return # decodation = self.client.fetchImage(self.location) # self.laatstGenomen2 = PhotoImage(file=self.location) # self.lblFotoLaatstGenomen.configure(image = self.laatstGenomen2) # self.vertalingString.set("VERTALING: " + str(decodation)) #make picture def makePicture(self): if not self.connected: return decodation = self.client.fetchImage("latestPicture.jpg") #tekst weergeven in debug venster def debugPrint(self, tekst): self.scrDebug.config(state = "normal") self.scrDebug.insert(END, ">> " + tekst + "\n") self.scrDebug.config(state = "disabled") self.scrDebug.yview_pickplace("end") def moveForward(self): if not self.connected or self.automaticFlag: return self.debugPrint("Voorwaarts vliegen aangevraagd") self.client.flyForward() def moveBackward(self): if not self.connected or self.automaticFlag: return self.debugPrint("Achterwaarts vliegen aangevraagd") self.client.flyBackward() def moveLeft(self): if not self.connected or self.automaticFlag: return self.debugPrint("Links draaien aangevraagd") self.client.turnLeft() def moveRight(self): if not self.connected or self.automaticFlag: return self.debugPrint("Rechts draaien aangevraagd") self.client.turnRight() def moveUp(self): if not self.connected or self.automaticFlag: return self.debugPrint("Omhoog vliegen aangevraagd") if(self.correctieFlag): self.toggleHeightCorrection() self.client.motorUpBackward() def moveDown(self): if not self.connected or self.automaticFlag: return self.debugPrint("Omlaag vliegen aangevraagd") if(self.correctieFlag): self.toggleHeightCorrection() self.client.motorUpForward() def landen(self): if not self.connected or self.automaticFlag: return self.debugPrint("Landen aangevraagd") self.client.stopAllMotors() def horizontalOff(self): if not self.connected or self.automaticFlag: return self.debugPrint("Horizontale motors stoppen aangevraagd") self.client.stopHorizontalMotors() def verticalOff(self): if not self.connected or self.automaticFlag: return self.debugPrint("Verticale motor stoppen aangevraagd") self.client.motorUpStop() #toetsenbord invoer def keyPressed(self, event): k = event.keysym if k == 'Up': if not self.btnUpPressed: self.btnUpPressed = True self.btnForward.config(bg = "orange red") self.btnForward.invoke() elif k == 'Down': if not self.btnDownPressed: self.btnDownPressed = True self.btnBackward.config(bg = "orange red") self.btnBackward.invoke() elif k == 'Left': if not self.btnLeftPressed: self.btnLeftPressed = True self.btnLeft.config(bg = "orange red") self.btnLeft.invoke() elif k == 'Right': if not self.btnRightPressed: self.btnRightPressed = True self.btnRight.config(bg = "orange red") self.btnRight.invoke() elif k == 'plus': if not self.btnPlusPressed: self.btnPlusPressed = True self.btnUp.config(bg = "orange red") self.btnUp.invoke() elif k == 'minus': if not self.btnMinusPressed: self.btnMinusPressed = True self.btnDown.config(bg = "orange red") self.btnDown.invoke() def keyReleased(self, event): k = event.keysym if k == 'Up': self.btnUpPressed = False self.btnForward.config(bg = "green") self.horizontalOff() elif k == 'Down': self.btnDownPressed = False self.btnBackward.config(bg = "green") self.horizontalOff() elif k == 'Left': self.btnLeftPressed = False self.btnLeft.config(bg = "green") self.horizontalOff() elif k == 'Right': self.btnRightPressed = False self.btnRight.config(bg = "green") self.horizontalOff() elif k == 'plus': self.btnPlusPressed = False self.btnUp.config(bg = "green") self.verticalOff() elif k == 'minus': self.btnMinusPressed = False self.btnDown.config(bg = "green") self.verticalOff() def updateAutomatic(self, info): if info[0]: if not info[1] == "": if not info[1] == self.lastCommandoString: self.lastCommandoString = info[1] self.debugPrint(info[1]) self.vertalingString.set("VERTALING: " + info[2]) with open(self.location, "wb") as handle: handle.write(info[3].data) self.laatstGenomen2 = PhotoImage(file=self.location) self.lblFotoLaatstGenomen.configure(image = self.laatstGenomen2) def updateInfo(self, info): global realHeight if info[0] != -1: self.gemetenHoogteString.set(str(info[0])) self.motorUpString.set(info[1]) if info[1] == "V" or info[1] == "A": self.lblmotorUpString.config(fg = "green") self.lblmotorUpStringValue.config(fg = "green") else: self.lblmotorUpString.config(fg = "red") self.lblmotorUpStringValue.config(fg = "red") self.motorLeftString.set(info[2]) if info[2] == "V" or info[2] == "A": self.lblmotorLeftString.config(fg = "green") self.lblmotorLeftStringValue.config(fg = "green") else: self.lblmotorLeftString.config(fg = "red") self.lblmotorLeftStringValue.config(fg = "red") self.motorRightString.set(info[3]) if info[3] == "V" or info[3] == "A": self.lblmotorRightString.config(fg = "green") self.lblmotorRightStringValue.config(fg = "green") else: self.lblmotorRightString.config(fg = "red") self.lblmotorRightStringValue.config(fg = "red") self.motorPWMString.set(str(math.ceil(info[4]))) self.correctieFlag = info[5] if(not self.correctieFlag): self.btnCorrectie.config(bg = "green") else: self.btnCorrectie.config(bg = "dark green") self.automaticFlag = info[6] if(not self.automaticFlag): self.btnAutomaticPilot.config(bg = "green") else: self.btnAutomaticPilot.config(bg = "dark green")
def createWidgets(self): '''Create and align widgets''' top = self.winfo_toplevel() top.rowconfigure(0, weight=1) top.columnconfigure(0, weight=1) self.rowconfigure(0, weight=1) self.columnconfigure(0, weight=1) self.passwordout = StringVar() self.passwordout.set('- No password generated -') self.isnew = IntVar() ttitle = Label(self, text=versionStr, font=self.getFont(4)) wisnew = Checkbutton(self, height=2, font=self.getFont(), text=('This is a new password, that I have not ' 'used before'), variable=self.isnew, command=self.toggleCheck) tlabel = Label(self, text='Label', font=self.getFont(2)) tpasswordin1 = Label(self, text='Password', font=self.getFont(2)) tpasswordin2 = Label(self, text='Password (again)', font=self.getFont(2)) tlength = Label(self, text='Length', font=self.getFont(2)) talgorithm = Label(self, text='Algorithm', font=self.getFont(2)) tsequence = Label(self, text='Sequence #', font=self.getFont(2)) self.label = ttk.Combobox(self, width=27, font=self.getFont(), postcommand=self.filterLabels) self.passwordin1 = Entry(self, width=27, font=self.getFont(), show="*") self.passwordin2 = Entry(self, width=27, font=self.getFont(), show="*", state=DISABLED) length = Spinbox(self, width=3, font=self.getFont, from_=9, to=171, textvariable=self.lengthVar) self.algorithm = ttk.Combobox(self, width=27, font=self.getFont(), values=algos.algorithms) sequence = Spinbox(self, width=3, font=self.getFont, from_=1, to=sys.maxint, textvariable=self.sequenceVar) genbutton = Button(self, text="Generate password", font=self.getFont(), command=self.validateAndShow, default="active") clrbutton = Button(self, text="Clear fields", font=self.getFont(), command=self.clearIO) self.result = Entry(self, font=self.getFont(4), textvariable=self.passwordout, state="readonly", fg="black", readonlybackground="gray") # Keybindings self.passwordin1.bind('<Return>', lambda e: genbutton.invoke()) self.passwordin2.bind('<Return>', lambda e: genbutton.invoke()) length.bind('<Return>', lambda e: genbutton.invoke()) self.algorithm.bind('<Return>', lambda e: genbutton.invoke()) sequence.bind('<Return>', lambda e: genbutton.invoke()) self.master.bind('<Control-q>', lambda e: self.quit()) self.master.bind('<Escape>', lambda e: self.reset()) self.label.bind('<<ComboboxSelected>>', self.labelSelected) self.label.bind('<FocusOut>', self.labelFocusOut) # Layout widgets in a grid ttitle.grid(row=0, column=0, sticky=N + S + E + W, columnspan=2) wisnew.grid(row=1, column=0, sticky=N + S + E + W, columnspan=2) tlabel.grid(row=2, column=0, sticky=N + S + W) self.label.grid(row=2, column=1, sticky=N + S + E + W) tpasswordin1.grid(row=3, column=0, sticky=N + S + W) self.passwordin1.grid(row=3, column=1, sticky=N + S + E + W) tpasswordin2.grid(row=4, column=0, sticky=N + S + W) self.passwordin2.grid(row=4, column=1, sticky=N + S + E + W) tlength.grid(row=5, column=0, sticky=N + S + W) length.grid(row=5, column=1, sticky=N + S + E + W) talgorithm.grid(row=6, column=0, sticky=N + S + W) self.algorithm.grid(row=6, column=1, sticky=N + S + E + W) tsequence.grid(row=7, column=0, sticky=N + S + W) sequence.grid(row=7, column=1, sticky=N + S + E + W) clrbutton.grid(row=8, column=0, sticky=N + S + E + W, columnspan=2) genbutton.grid(row=9, column=0, sticky=N + S + E + W, columnspan=2) self.result.grid(row=10, column=0, sticky=N + S + E + W, columnspan=2) # Initial values self.algorithm.set(self.settings.algorithm) # Initially, set focus on self.label self.label.focus_set()