PYTHON:Tkinter.OptionMenu Question : option menu does not execute the command function to user selection -


i trying create python program below. reads file bus time table , in tkinter, displays departure list , arrival bus stops corresponding time.

here using following code update time each departure or arrival stops. when select stops not call functions. not understand why.

tkinter.optionmenu(self.root,self.departure,*self.busstops,command=self.update_departure()).pack() tkinter.optionmenu(self.root,self.arrival,*self.busstops,command=self.update_arrival()).pac 

can throw light on it?

the same works if not use class structure.

i running on windows xp 2002 service pack 2 python 2.6 version import tkinter import time

class app():     def __init__(self):     self.root  = tkinter.tk()     self.debug_enable = 1      self.timetable_file_name = "200_timetable.txt"     self.busstops    = list()     self.arrivaltime = list()     self.update_timetable()      self.departure   = tkinter.stringvar()     self.arrival     = tkinter.stringvar()     self.starttime   = tkinter.stringvar()     self.endtime     = tkinter.stringvar()      self.label = tkinter.label(text="")     self.label.pack()     self.update_clock()      self.departure.set(self.busstops[0])     self.arrival.set(self.busstops[-1])     self.starttime.set("hi")     self.endtime.set("ih")      self.optmenudep= tkinter.optionmenu(self.root,self.departure,*self.busstops,command=self.update_departure()).pack()     self.optmenuarr= tkinter.optionmenu(self.root,self.arrival,*self.busstops,command=self.update_arrival()).pack()     self.optmenudeptime = tkinter.optionmenu(self.root,self.starttime,"").pack()     self.optmenuarrtime = tkinter.optionmenu(self.root,self.endtime,"").pack()      self.root.mainloop()      def debug(self,message):     if self.debug_enable:        print "debug message : ", message      def update_clock(self):     = time.strftime("%h:%m:%s")     self.label.configure(text=now)     self.root.after(200, self.update_clock)      def update_timetable(self):     self.file_desc = open(self.timetable_file_name)     line in self.file_desc.readlines():         self.busstops.append(line.split('\t')[0])         self.arrivaltime.append(line.split('\t')[2:-1])     self.file_desc.close()      def update_departure(self):     self.debug("entering update departure")     stop_name = self.departure.get()     count = 0     stop in self.busstops:         if (stop == stop_name):            break         else:            count += 1     self.starttime.set(self.arrivaltime[count])     count = 0      def update_arrival(self):     self.debug("entering update arrival")     stop_name = self.arrival.get()     count = 0     stop in self.busstops:         if (stop == stop_name):            break         else:            count += 1     self.endtime.set(self.arrivaltime[count])     count = 0  # main program starts here  app=app() 

""""""""""""""""""""""""" data format below file 200_timetable.txt

nice - station j.c. bermond 07:30 07:45 08:00 08:10 08:15 08:30

nice - j. médecin / hôtel des postes 07:32 07:47 08:02 08:12 08:17 08:32

nice - grimaldi 07:33 07:48 08:03 08:13 08:18 08:33

nice - rivoli 07:34 07:49 08:04 08:14 08:19 08:34

""""""""""""""""""""""""""""

when write command=self.update_departure() saying "execute command self._update_departure, , use result of call name of command". since self._update_departure() returns none, it's same doing command=none

in other words, omit () -- need pass reference function.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -