Foros del Web » Programando para Internet » Python »

Python Botones <Atras----Siguiente>

Estas en el tema de Python Botones <Atras----Siguiente> en el foro de Python en Foros del Web. Buenas tengo un programa al ejecutar los botones de atrás y siguiente, el problema es que cuando le doy siguiente no me borra o me ...
  #1 (permalink)  
Antiguo 21/10/2011, 13:40
 
Fecha de Ingreso: octubre-2011
Mensajes: 31
Antigüedad: 12 años, 6 meses
Puntos: 7
Python Botones <Atras----Siguiente>

Buenas tengo un programa al ejecutar los botones de atrás y siguiente, el problema es que cuando le doy siguiente no me borra o me quita la ventana anterior... y cuando le doy atrás no me borra la otra... entonces tengo toda ese poco ve ventanas... si por favor me pudieran ayudar con un ejemplo.. que de siguiente y borre la ventana anterior o viceversa estaría muy agradecido.... estoy trabajando con python gtk 2 gracias...
  #2 (permalink)  
Antiguo 21/10/2011, 20:21
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Python Botones <Atras----Siguiente>

Si no posteas algo de código con el que estas trabajando no te puedo a ciencia cierta que estas haciendo mal o que necesitas corregir.
  #3 (permalink)  
Antiguo 24/10/2011, 07:34
 
Fecha de Ingreso: octubre-2011
Mensajes: 31
Antigüedad: 12 años, 6 meses
Puntos: 7
Respuesta: Python Botones <Atras----Siguiente>

hola amigo mire tengo este código que tiene 3 ventanas la cual tiene botones de atrás y siguiente.. pero cuando da siguiente la otra ventana se queda... ejemplo : la ventana 2 da siguiente y busca la ventana 3, pero la ventana 2 sigue estando visible y no se quita como hago para que la ventana 2 llama a la tres y se destruya o no este visible... al igual que la ventana 3 tiene un botón de atrás el cual llama a la ventana 2 pero se queda la ventana 3... entonces quedaría con muchas ventanas innecesarias... si me puedes ayudar gracias aquí esta el código

Código Python:
Ver original
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. #pygtk.require('2.0')
  4.  
  5. import gtk
  6. #-----------------------------------ventana 3---------------------------
  7. def ventana3(self):
  8.     window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  9.     window.set_title("ventana3")
  10.     window.set_border_width(10)
  11.     window.set_size_request(520, 440)
  12.     window.set_resizable(False)
  13.  
  14.    
  15.    
  16.     def make_box1(homogeneous, spacing, expand, fill, padding):
  17.            
  18.         caja = gtk.HBox(homogeneous, spacing)
  19.         caja.set_border_width(10)
  20.            
  21.         boton = gtk.Button("  <Atras  ")
  22.         boton.connect("clicked", ventana2)
  23.         caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 0)
  24.         boton.show()
  25.            
  26.         boton = gtk.Button(" Siguiente> ")
  27.         #boton.connect("clicked", ventana3)
  28.         caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 0)
  29.         boton.show()
  30.         return caja
  31.    
  32.    
  33.     vbox = gtk.VBox(gtk.FALSE, 0)
  34.    
  35.    
  36.     box2 = make_box1(gtk.FALSE, 0, gtk.FALSE, gtk.FALSE,0)
  37.     vbox.pack_start(box2, gtk.FALSE, gtk.FALSE, 0)
  38.     box2.show()
  39.    
  40.    
  41.     window.add(vbox)
  42.     window.show_all()
  43.  
  44. #-----------------------------------ventana 2 --------------------------
  45. def ventana2(self):
  46.     window = gtk.Window(gtk.WINDOW_TOPLEVEL)
  47.     window.set_title("ventana2")
  48.     window.set_border_width(10)
  49.     window.set_size_request(520, 440)
  50.     window.set_resizable(False)
  51.  
  52.    
  53.    
  54.     def make_box1(homogeneous, spacing, expand, fill, padding):
  55.            
  56.         caja = gtk.HBox(homogeneous, spacing)
  57.         caja.set_border_width(10)
  58.            
  59.         boton = gtk.Button("  <Atras  ")
  60.         #boton.connect("clicked", )
  61.         caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 100)
  62.         boton.show()
  63.            
  64.         boton = gtk.Button(" Siguiente> ")
  65.         boton.connect("clicked", ventana3)
  66.         caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 50)
  67.         boton.show()
  68.         return caja
  69.    
  70.    
  71.     vbox = gtk.VBox(gtk.FALSE, 0)
  72.    
  73.    
  74.     box2 = make_box1(gtk.FALSE, 0, gtk.FALSE, gtk.FALSE,0)
  75.     vbox.pack_start(box2, gtk.FALSE, gtk.FALSE, 0)
  76.     box2.show()
  77.    
  78.    
  79.     window.add(vbox)
  80.     window.show_all()
  81. #-----------------------------------ventana 2--------------------------
  82.  
  83.  
  84. #--------------------------------------ventana 1--------------------------
  85. class MyApp():
  86.  
  87.     def __init__(self):
  88.         self.window = gtk.Window()
  89.         self.window.set_border_width(0)
  90.         self.window.set_title("ventana1")
  91.         self.window.set_size_request(520, 715)
  92.         self.window.set_resizable(False)
  93.        
  94.        
  95.        
  96.         def make_box4(homogeneous, spacing, expand, fill, padding):
  97.            
  98.             caja = gtk.HBox(homogeneous, spacing)
  99.             caja.set_border_width(10)
  100.            
  101.             boton = gtk.Button(stock=gtk.STOCK_CLOSE)
  102.             boton.connect("clicked", gtk.mainquit)
  103.             caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 60)
  104.             boton.show()
  105.            
  106.             boton = gtk.Button("Siguiente>")
  107.             boton.connect("clicked", ventana2)
  108.             caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 220)
  109.             boton.show()
  110.             return caja
  111.        
  112.        
  113.         self.vbox = gtk.VBox(gtk.FALSE, 0)
  114.        
  115.        
  116.        
  117.         self.box2 = make_box4(gtk.FALSE, 0, gtk.FALSE, gtk.FALSE,0)
  118.         self.vbox.pack_start(self.box2, gtk.FALSE, gtk.FALSE, 0)
  119.         self.box2.show()
  120.        
  121.        
  122.        
  123.         self.window.add(self.vbox)
  124.         self.window.connect("destroy", gtk.main_quit)
  125.         self.window.show_all()
  126. #-------------------------------ventana 1---------------------------  
  127. if __name__ == "__main__":
  128.     app = MyApp()
  129.     gtk.main()
..

Última edición por razpeitia; 24/10/2011 a las 22:28
  #4 (permalink)  
Antiguo 24/10/2011, 22:28
Avatar de razpeitia
Moderador
 
Fecha de Ingreso: marzo-2005
Ubicación: Monterrey, México
Mensajes: 7.321
Antigüedad: 19 años, 1 mes
Puntos: 1360
Respuesta: Python Botones <Atras----Siguiente>

Tienes mucho código que se repite te recomiendo hacer clases o métodos mas generales.

Código Python:
Ver original
  1. #coding: cp1252
  2.  
  3. import gtk
  4.  
  5. class Ventana(gtk.Window):
  6.     def __init__(self, title, size, resizable=False):
  7.         gtk.Window.__init__(self, gtk.WINDOW_TOPLEVEL)
  8.         self.set_position(gtk.WIN_POS_CENTER)
  9.        
  10.         self.nextWindow = None
  11.         self.backWindow = None
  12.        
  13.         self.set_title(title)
  14.         self.set_border_width(10)
  15.         self.set_size_request(*size)
  16.         self.set_resizable(resizable)
  17.        
  18.         self.hbox = gtk.HBox()
  19.         self.back = gtk.Button("Back")
  20.         self.next = gtk.Button("Next")
  21.        
  22.         self.add(self.hbox)
  23.         self.hbox.add(self.back)
  24.         self.hbox.add(self.next)
  25.        
  26.         self.next.connect("clicked", self.onNext)
  27.         self.back.connect("clicked", self.onBack)
  28.         self.connect("destroy", self.onDestroy)
  29.    
  30.     def onDestroy(self, event):
  31.         gtk.main_quit()
  32.        
  33.     def onBack(self, event):
  34.         if self.backWindow is not None:
  35.             self.hide()
  36.             self.backWindow.show_all()
  37.        
  38.    
  39.     def onNext(self, event):
  40.         if self.nextWindow is not None:
  41.             self.hide()
  42.             self.nextWindow.show_all()
  43.        
  44. class MyApp():
  45.  
  46.     def __init__(self):
  47.         ventana1 = Ventana("Ventana 1", (300, 50))
  48.         ventana2 = Ventana("Ventana 2", (300, 50))
  49.         ventana3 = Ventana("Ventana 3", (300, 50))
  50.        
  51.         ventana1.nextWindow = ventana2
  52.         ventana2.nextWindow = ventana3
  53.        
  54.         ventana3.backWindow = ventana2
  55.         ventana2.backWindow = ventana1
  56.        
  57.         ventana1.show_all()
  58.        
  59.  
  60. if __name__ == "__main__":
  61.     app = MyApp()
  62.     gtk.main()
  #5 (permalink)  
Antiguo 25/10/2011, 07:50
 
Fecha de Ingreso: octubre-2011
Mensajes: 31
Antigüedad: 12 años, 6 meses
Puntos: 7
Respuesta: Python Botones <Atras----Siguiente>

buenas amigo muchas gracias por tu respuesta voy a revisarlo para adaptarlo al código que yo tengo...
  #6 (permalink)  
Antiguo 25/10/2011, 12:54
 
Fecha de Ingreso: octubre-2011
Mensajes: 31
Antigüedad: 12 años, 6 meses
Puntos: 7
Respuesta: Python Botones <Atras----Siguiente>

buenas amigo como esta mucha gracias por sus respuestas... mire tengo un problema yo estoy trabajando por módulos.... tengo la ventana 1 es un archivo y la 2 es otro archivo la 2 llama a la 3 con un botón de siguiente y la 3 llama a las 2 con un botón de atrás pero no logro que las ventanas se me oculten cuando me muestra una o la otra aquí le dejo el código a ver si me puede ayudar gracias...

nota: los dos archivos deben estar guardados en la misma dirección con los nombre ventana2 y ventana3
###################ventana2#######################
Código:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#pygtk.require('2.0')
#-------------------------MODULO 1 --------------------------------- 
###############################################################################################
#---------------------Este archivo debe guardarse con el nombre ventana2.py---------------------
################################################################################################
import gtk
import ventana3 #IMPORTANDO EL MODULO 2
#--------------------------------------ventana 1--------------------------
class MyApp():
 
    def __init__(self):
        self.window = gtk.Window()
        self.window.set_border_width(0)
        self.window.set_title("ventana1")
        self.window.set_size_request(520, 715)
        self.window.set_resizable(False)
        
        def llamando_al_modulo2(self, data=None):
			ventana3.MyApp1()
        
        def make_box4(homogeneous, spacing, expand, fill, padding):
            
            caja = gtk.HBox(homogeneous, spacing)
            caja.set_border_width(10)
            
            boton = gtk.Button(stock=gtk.STOCK_CLOSE)
            boton.connect("clicked", gtk.mainquit)
            caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 60)
            boton.show()
            
            boton = gtk.Button("Siguiente>")
            boton.connect("clicked", llamando_al_modulo2)#conecta con la ventana 3
            caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 220)
            boton.show()
            return caja
        
        
        self.vbox = gtk.VBox(gtk.FALSE, 0)
        
        
        
        self.box2 = make_box4(gtk.FALSE, 0, gtk.FALSE, gtk.FALSE,0)
        self.vbox.pack_start(self.box2, gtk.FALSE, gtk.FALSE, 0)
        self.box2.show()
        
        
        
        self.window.add(self.vbox)
        self.window.connect("destroy", gtk.main_quit)
        self.window.show_all()
#-------------------------------ventana 1---------------------------  
if __name__ == "__main__":
    app = MyApp()
    gtk.main()
##########################ventana3################ ########
Código:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#pygtk.require('2.0')
#--------------------------MODULO 2 -------------------------- 
###############################################################################################
#---------------------Este archivo debe guardarse con el nombre ventana3.py---------------------
################################################################################################
import gtk
import ventana2#IMPORTANDO EL MODULO 1
#--------------------------------ventana2---------------------
class MyApp1():
 
    def __init__(self):
        self.window = gtk.Window()
        self.window.set_border_width(0)
        self.window.set_title("ventana2")
        self.window.set_size_request(520, 200)
        self.window.set_resizable(False)
        
        def llamando_al_modulo1(self, data=None):
			ventana2.MyApp()
        
        def make_box1(homogeneous, spacing, expand, fill, padding):
            
            caja = gtk.HBox(homogeneous, spacing)
            caja.set_border_width(10)
		
            boton = gtk.Button("<Atras")
            boton.connect("clicked",llamando_al_modulo1 )#conecta con la ventana2 
            caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 60)
            boton.show()
            
            boton = gtk.Button(stock=gtk.STOCK_HELP)
            #boton.connect("clicked", )
            caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 60)
            boton.show()
            
            boton = gtk.Button("Aceptar")
            #boton.connect("clicked", )
            caja.pack_start(boton, gtk.FALSE, gtk.FALSE, 60)
            boton.show()
            return caja
        
        
        self.vbox = gtk.VBox(gtk.FALSE, 0)
        

        self.box2 = make_box1(gtk.FALSE, 0, gtk.FALSE, gtk.FALSE,0)
        self.vbox.pack_start(self.box2, gtk.FALSE, gtk.FALSE, 0)
        self.box2.show()
        
        
        
        self.window.add(self.vbox)
        self.window.connect("destroy", gtk.main_quit)
        self.window.show_all()
#-------------------------------ventana 2---------------------------  
if __name__ == "__main__":
    app = MyApp1()
    gtk.main()

Etiquetas: botones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:57.