Foros del Web » Programando para Internet » Python »

[SOLUCIONADO] Problemas con Tkinter y button

Estas en el tema de Problemas con Tkinter y button en el foro de Python en Foros del Web. Que tal amigos, soy nuevo en este lenguaje y trato de de hacer una pequeña interfaz con algunos elementos visibles, sin embargo estoy teniendo algunos ...
  #1 (permalink)  
Antiguo 01/07/2013, 02:49
 
Fecha de Ingreso: julio-2013
Ubicación: México
Mensajes: 10
Antigüedad: 10 años, 10 meses
Puntos: 0
Información Problemas con Tkinter y button

Que tal amigos, soy nuevo en este lenguaje y trato de de hacer una pequeña interfaz con algunos elementos visibles, sin embargo estoy teniendo algunos problemas con los Button, ojala me puedan ayudar, este es el codigo:

Código:
from Tkinter import *
from tkFileDialog import *
from ttk import *
from numpy import *
from matplotlib.pyplot import *

def abrir():
    archivo = askopenfilename(filetypes = [("Archivos de Texto",".txt")])    
    entry.insert(0, archivo)
    ruta = entry.get()
    lbl_ruta = Label(frame, text = ruta)
    lbl_ruta.pack()
    return archivo

def graficar():
    x = arange(0, 10, 0.1)
    y = 2*sin(4*x)-x**2+10*x 
    plot(x, y)
    show()
    
opciones = (1,2,3)

root = Tk()
root.minsize(400, 300)
root.title("Prueba")

frame = Frame(root)
panel = Labelframe(frame, text = "Carga de archivo")
label = Label(panel, text = "Archivo de datos:")
entry = Entry(panel)
button = Button(frame, text = "Examinar...", command = abrir)
combo = Combobox(panel, values = opciones)
grafica = Button(frame, text = "Graficar")
lbl = Label (panel, text=combo.get())

frame.pack()
panel.pack(in_ = frame, side = TOP, pady = 5, padx = 10)
label.pack(pady = 5, padx = 10)
entry.pack(pady = 5, padx = 10)
button.pack(pady = 5, padx = 10)
combo.pack(pady = 5, padx = 10)
grafica.pack(pady = 5, padx = 10)
lbl.pack(pady = 5, padx = 10)

combo.current(0)

root.mainloop()
y este es el error que me arroja:

Código:
Traceback (most recent call last):
  File "/home/osvaldo/Escritorio/Proyecto/nueva.py", line 31, in <module>
    button = Button(frame, text = "Examinar...", command = abrir)
TypeError: __init__() got an unexpected keyword argument 'text'
estoy compilando con Python 2.7
  #2 (permalink)  
Antiguo 01/07/2013, 09:30
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: Problemas con Tkinter y button

Por favor no uses import *, por que después no sabes ni lo que tienes en tu namespace. Justo como en este caso. Donde habían 2 clases Button y agarraba la de matplot.

Código Python:
Ver original
  1. from Tkinter import *
  2. from tkFileDialog import *
  3. from ttk import *
  4. from numpy import arange, sin
  5. from matplotlib.pyplot import plot, show
  6.  
  7. def abrir():
  8.     archivo = askopenfilename(filetypes = [("Archivos de Texto",".txt")])    
  9.     entry.insert(0, archivo)
  10.     ruta = entry.get()
  11.     lbl_ruta = Label(frame, text = ruta)
  12.     lbl_ruta.pack()
  13.     return archivo
  14.  
  15. def graficar():
  16.     x = arange(0, 10, 0.1)
  17.     y = 2*sin(4*x)-x**2+10*x
  18.     plot(x, y)
  19.     show()
  20.    
  21. opciones = (1,2,3)
  22.  
  23. root = Tk()
  24. root.minsize(400, 300)
  25. root.title("Prueba")
  26.  
  27. frame = Frame(root)
  28. panel = Labelframe(frame, text = "Carga de archivo")
  29. label = Label(panel, text = "Archivo de datos:")
  30. entry = Entry(panel)
  31. button = Button(frame, text="Examinar...", command=abrir)
  32. combo = Combobox(panel, values = opciones)
  33. grafica = Button(frame, text="Graficar", command=graficar)
  34. lbl = Label (panel, text=combo.get())
  35.  
  36. frame.pack()
  37. panel.pack(in_ = frame, side = TOP, pady = 5, padx = 10)
  38. label.pack(pady = 5, padx = 10)
  39. entry.pack(pady = 5, padx = 10)
  40. button.pack(pady = 5, padx = 10)
  41. combo.pack(pady = 5, padx = 10)
  42. grafica.pack(pady = 5, padx = 10)
  43. lbl.pack(pady = 5, padx = 10)
  44.  
  45. combo.current(0)
  46.  
  47. root.mainloop()

PD: Es como la tercera vez que me preguntan esto diferentes personas, entonces supongo que es una tarea o proyecto final o lo que sea. Te recomiendo primero aprender python y leer un poco la documentación de las librerías que uses.
  #3 (permalink)  
Antiguo 01/07/2013, 12:59
 
Fecha de Ingreso: julio-2013
Ubicación: México
Mensajes: 10
Antigüedad: 10 años, 10 meses
Puntos: 0
Respuesta: Problemas con Tkinter y button

Cita:
Iniciado por razpeitia Ver Mensaje
Por favor no uses import *, por que después no sabes ni lo que tienes en tu namespace. Justo como en este caso. Donde habían 2 clases Button y agarraba la de matplot.

Código Python:
Ver original
  1. from Tkinter import *
  2. from tkFileDialog import *
  3. from ttk import *
  4. from numpy import arange, sin
  5. from matplotlib.pyplot import plot, show
  6.  
  7. def abrir():
  8.     archivo = askopenfilename(filetypes = [("Archivos de Texto",".txt")])    
  9.     entry.insert(0, archivo)
  10.     ruta = entry.get()
  11.     lbl_ruta = Label(frame, text = ruta)
  12.     lbl_ruta.pack()
  13.     return archivo
  14.  
  15. def graficar():
  16.     x = arange(0, 10, 0.1)
  17.     y = 2*sin(4*x)-x**2+10*x
  18.     plot(x, y)
  19.     show()
  20.    
  21. opciones = (1,2,3)
  22.  
  23. root = Tk()
  24. root.minsize(400, 300)
  25. root.title("Prueba")
  26.  
  27. frame = Frame(root)
  28. panel = Labelframe(frame, text = "Carga de archivo")
  29. label = Label(panel, text = "Archivo de datos:")
  30. entry = Entry(panel)
  31. button = Button(frame, text="Examinar...", command=abrir)
  32. combo = Combobox(panel, values = opciones)
  33. grafica = Button(frame, text="Graficar", command=graficar)
  34. lbl = Label (panel, text=combo.get())
  35.  
  36. frame.pack()
  37. panel.pack(in_ = frame, side = TOP, pady = 5, padx = 10)
  38. label.pack(pady = 5, padx = 10)
  39. entry.pack(pady = 5, padx = 10)
  40. button.pack(pady = 5, padx = 10)
  41. combo.pack(pady = 5, padx = 10)
  42. grafica.pack(pady = 5, padx = 10)
  43. lbl.pack(pady = 5, padx = 10)
  44.  
  45. combo.current(0)
  46.  
  47. root.mainloop()

PD: Es como la tercera vez que me preguntan esto diferentes personas, entonces supongo que es una tarea o proyecto final o lo que sea. Te recomiendo primero aprender python y leer un poco la documentación de las librerías que uses.

muchas gracias, en eso estoy... aprendiendo

Etiquetas: interfaz
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 04:30.