Calificación:
  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
¿Como puedo referirme a un botón fuera de su clase?
#1
Soy nuevo en el foro y debo decir que también programando. Aunque puede resultar ridícula llevo algún tiempo con una duda que pese a mi empeño no he conseguido solucionar.
Código:
from Tkinter import *
import Tkinter

#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
# como tengo que referirme al botónn para que la función
# cambie el texto??.
def Otro_Texto():
 
   if Boton['text'] == "Conectar":
       Boton.configure(text='xxxxxrfdfdfdf')
               
#XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX  

class pantalla:

   def Ventana_Frame(self):
       self.Frame_Conf = Frame(Ventana, width=157, height=60, bd="0", highlightthickness=0)
       self.Frame_Conf.place(x="10",y="50")
       
       self.Boton = Button(self.Frame_Conf, text="Funcion_Otro_Texto",width="18", font=("Comic Sans MS",9), command=Otro_Texto).place(x="10",y="10")

obj_pantalla=pantalla()


if __name__ == '__main__':  
   
   Ventana = Tkinter.Tk()
   Ventana.title("Ventana")
   Ventana.configure(background="#0a0000")
   btn_Abri_conexi = Button(Ventana, text="Abrir_Frame_Conf",width="18", font=("Comic Sans MS",9), command=obj_pantalla.Ventana_Frame).place(x="20",y="10")

Ventana.mainloop()


Estaría muy agradecido si alguien me pudiese orientar. Muchas gracias
Responder
#2
Hola, bienvenido. Simplemente creas tu función adentro de la clase, así podras acceder al botón como self.Boton.

  1. class pantalla:
  2.  
  3. def Ventana_Frame(self):
  4. self.Frame_Conf = Frame(Ventana, width=157, height=60, bd="0", highlightthickness=0)
  5. self.Frame_Conf.place(x="10",y="50")
  6. self.Boton = Button(self.Frame_Conf, text="Funcion_Otro_Texto",width="18", font=("Comic Sans MS",9), command=self.Otro_Texto)
  7.  
  8. def Otro_Texto(self):
  9. if self.Boton['text'] == "Conectar":
  10. self.Boton.configure(text='xxxxxrfdfdfdf')


Saludos
¡No te pierdas nuestro curso oficial en Udemy para aprender Python, bases de datos SQL, orientación a objetos, tkinter y mucho más!
Responder
#3
Muchísimas gracias.
Existe la posibilidad de acceder fuera de la clase??
Responder
#4
Sí, usando el nombre de la instancia:

  1. obj_pantalla.Boton.configure(...)
¡No te pierdas nuestro curso oficial en Udemy para aprender Python, bases de datos SQL, orientación a objetos, tkinter y mucho más!
Responder
#5
Muchísimas gracias otra vez, fuiste de gran ayuda.
Responder
#6
De nada! Wink
¡No te pierdas nuestro curso oficial en Udemy para aprender Python, bases de datos SQL, orientación a objetos, tkinter y mucho más!
Responder


Salto de foro:


Usuarios navegando en este tema: 1 invitado(s)