tkinter - Assign OptionMenu Variable in python -


i working on menu system allows user select date , location access specific file. know lot of hard coding each specific file. want use optionmenu system. getting values printed, how can define these values , pass them through function open specific file. thinking long if else statement. (ie if monday && pass call function).

here code

#mainmenu class myoptionmenu(optionmenu):  def __init__(self, master, status, *options):     self.var = stringvar(master)     self.var.set(status)     optionmenu.__init__(self, master, self.var, *options)     self.config(font=('calibri',(20)),bg='white',width=20)     self['menu'].config(font=('calibri',(10)),bg='white')  root = tk() #attemtping assign numerical values monday = 1 tuesday = 2 wednesday = 3 thursday = 4 friday = 5 mymenu1 = myoptionmenu(root, 'select day', 'monday','tuesday','wednesday', 'thursday', 'friday') mymenu2 = myoptionmenu(root, 'select location', 'd','e','f') #menus come fine , values correctly printed def ok(): print "value is", (mymenu1.var).get(), (mymenu2.var).get() button = button(root, text="ok", command=ok) button.pack() mymenu1.pack() mymenu2.pack() (mymenu1.var).get() (mymenu2.var).get() #assign variable x return values x = (mymenu1.var).get() if x <2:     print 'negative changed zero' elif x == 0:     print 'zero' elif x == 1:     print 'single' else:     print 'more'  root.mainloop() 

i getting output "more"/ "value monday e", shows able access correct outcome, lost on implementing variable (tuesday) in next step.

thank in advance

@justforfun, question little tangled , bit hard contemplate, think understand want. firstly have put last part @ wrong place (from #assign variable x return values), run through @ start, not after ok button clicked, x equal 'select day' (thus why more printed when run it), should put inside function called in ok(), or in ok() itself:

def ok():     print "value is", (mymenu1.var).get(), (mymenu2.var).get()     x = (mymenu1.var).get()     if x <2:         print 'negative changed zero'     elif x == 0:         print 'zero'     elif x == 1:         print 'single'     else:         print 'more' 

this value x , test when ok clicked, , can lead more actions using results gained open file etc. but, have (i think) rushed last part if/elif etc statements first if...: pick items below 2 (<), next 2 elif statements aren't going evaluate true, intend have (>) in first statement? need include variable second optionmenu in if/elif statements:

if x > 2 , y == ...:     # open specific file? etc... 

i hope has helped you, not sure if wanted, if not , point me in right direction, cheers.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -