Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Python - funzione avviene prima di essere chiamata
Forum - Python - funzione avviene prima di essere chiamata

Avatar
Umberto (Member)
Pro


Messaggi: 156
Iscritto: 27/09/2011

Segnala al moderatore
Postato alle 19:22
Lunedì, 11/06/2012
Chiedo scusa per i post in serie su questa sezione.
Quando eseguo questo programma:
Codice sorgente - presumibilmente Python

  1. from Tkinter import *
  2. import sys
  3. import os
  4.      
  5. class Finestra(Tk):
  6.             def __init__(self):
  7.                     """Costruttore della classe Finestra
  8.                  """
  9.                     iargv = 1
  10.                     Tk.__init__(self)
  11.                     self.title(sys.argv[iargv])
  12.                     self.geometry("%dx%d" % (220, 150))
  13.                     i = 1
  14.                     while sys.argv[iargv] != "end":
  15.                         iargv = iargv + 1
  16.                         if sys.argv[iargv] == "button":
  17.                                 # creo il bottone
  18.                                 iargv = iargv + 1
  19.                                 buttontext = sys.argv[iargv]
  20.                                 iargv = iargv + 1
  21.                                 comm = sys.argv[iargv]
  22.                                 b = Button(self, text=buttontext, command=self.action(comm))
  23.                                 iargv = iargv + 1
  24.                                 locx = int(sys.argv[iargv])
  25.                                 iargv = iargv + 1
  26.                                 locy = int(sys.argv[iargv])
  27.                                 b.place(x=locx, y=locy)
  28.                                 i = i + 1
  29.                     # registro l'evento di chiusura della finestra        
  30.                     self.protocol('WM_DELETE_WINDOW', self.__chiudi)
  31.                    
  32.             def mostra(self):
  33.                     """Visualizza la finestra
  34.                  """
  35.                     # mando in loop l'applicazione
  36.                     self.mainloop()
  37.      
  38.             def action(self,comm):
  39.                     """Stampa sullo standard output la stringa 'Hello world !
  40.                  """
  41.                     print "here"
  42.                     os.system(comm)
  43.      
  44.             def __chiudi(self):
  45.                     """Chiude l'applicazione alla chiusura della finestra
  46.                  """
  47.                     self.destroy()
  48.                    
  49.                    
  50. if __name__ == '__main__':
  51.             f = Finestra()
  52.             f.mostra()


Prima di preme il bottone viene già avviata la funzione action :om:

PM Quote
Avatar
Umberto (Member)
Pro


Messaggi: 156
Iscritto: 27/09/2011

Segnala al moderatore
Postato alle 20:02
Mercoledì, 13/06/2012
Risolto!!
Codice sorgente - presumibilmente Python

  1. from Tkinter import *
  2. import sys
  3. import os
  4.      
  5. class Finestra(Tk):
  6.             def __init__(self):
  7.                     """Costruttore della classe Finestra
  8.                 """
  9.                     iargv = 1
  10.                     Tk.__init__(self)
  11.                     self.title(sys.argv[iargv])
  12.                     self.geometry("%dx%d" % (220, 150))
  13.                     i = 1
  14.                     while sys.argv[iargv] != "end":
  15.                         iargv = iargv + 1
  16.                         if sys.argv[iargv] == "button":
  17.                                 # creo il bottone
  18.                                 iargv = iargv + 1
  19.                                 buttontext = sys.argv[iargv]
  20.                                 iargv = iargv + 1
  21.                                 comm = sys.argv[iargv]
  22.                                 b = Button(self, text=buttontext, command=lambo: self.action(comm))
  23.                                 iargv = iargv + 1
  24.                                 locx = int(sys.argv[iargv])
  25.                                 iargv = iargv + 1
  26.                                 locy = int(sys.argv[iargv])
  27.                                 b.place(x=locx, y=locy)
  28.                                 i = i + 1
  29.                     # registro l'evento di chiusura della finestra        
  30.                     self.protocol('WM_DELETE_WINDOW', self.__chiudi)
  31.                    
  32.             def mostra(self):
  33.                     """Visualizza la finestra
  34.                 """
  35.                     # mando in loop l'applicazione
  36.                     self.mainloop()
  37.      
  38.             def action(self,comm):
  39.                     """Stampa sullo standard output la stringa 'Hello world !
  40.                 """
  41.                     print "here"
  42.                     os.system(comm)
  43.      
  44.             def __chiudi(self):
  45.                     """Chiude l'applicazione alla chiusura della finestra
  46.                 """
  47.                     self.destroy()
  48.                    
  49.                    
  50. if __name__ == '__main__':
  51.             f = Finestra()
  52.             f.mostra()


PM Quote