Foros del Web » Programando para Internet » Python »

[SOLUCIONADO] Tkinter Python, Como hago un raw_input en tkinter?

Estas en el tema de Tkinter Python, Como hago un raw_input en tkinter? en el foro de Python en Foros del Web. Python en mi primer lenguaje y lo aprendo porque me gusta, pero lo hago solo y a puro manual, asi que agradezco cualquier ayuda y ...
  #1 (permalink)  
Antiguo 29/06/2013, 02:21
 
Fecha de Ingreso: junio-2013
Mensajes: 9
Antigüedad: 10 años, 10 meses
Puntos: 0
Tkinter Python, Como hago un raw_input en tkinter?

Python en mi primer lenguaje y lo aprendo porque me gusta, pero lo hago solo y a puro manual, asi que agradezco cualquier ayuda y paciencia,

Tengo el siguiente programa escrito en Python, pero deseo que las constantes que coloco al inicio, las pueda introducir desde Tkinter como si fuera un raw_input. Tengo el programa base escrito, coloco una parte.

Código:
import math
import numpy
import matplotlib.pyplot

h = 0.1 # days                                                                      
transmission_coeff = 5e-9 # 1 / day persons                                                                                                                          
latency_time = 1. # days                                                            
infectious_time = 5. # days                                                         
end_time = 60.0 # days
num_steps = int(end_time / h)                                                       
times = h * numpy.array(range(num_steps + 1))

El asunto es que me encantaria que un template que encontre usarlo como base pero no me esta corriendo, cuando lo pego a python y me gustaria que alguien me indicara o como hago un raw_input para mi programa de Python o como se arregla el siguiente código. para que desde ahi ya comience solo ha hacerle los arreglos, este codigo va como sigue...

Código:
from tkinter import *
from tkinter import *

def calculate(*args):
    try:
        value = float(feet.get())
        meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0)
    except ValueError:
        pass
    
root = Tk()
root.title("Feet to Meters")

mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)

feet = StringVar()
meters = StringVar()

feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))

ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)

ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)

for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)

feet_entry.focus()
root.bind('<Return>', calculate)

root.mainloop()
De verdad agradezco cualquier ayuda

Saludos
Santiago
  #2 (permalink)  
Antiguo 29/06/2013, 12:04
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: Tkinter Python, Como hago un raw_input en tkinter?

No se de donde sacaste el ejemplo, pero es el peor ejemplo que he visto.

De cualquier forma arregle el código para que corriera.
Código Python:
Ver original
  1. from Tkinter import *
  2.  
  3. def calculate(*args):
  4.     try:
  5.         value = float(feet.get())
  6.         meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0)
  7.     except ValueError:
  8.         pass
  9.  
  10. root = Tk()
  11. root.title("Feet to Meters")
  12.  
  13. mainframe = Frame(root)
  14. mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
  15. mainframe.columnconfigure(0, weight=1)
  16. mainframe.rowconfigure(0, weight=1)
  17.  
  18. feet = StringVar()
  19. meters = StringVar()
  20.  
  21. feet_entry = Entry(mainframe, width=7, textvariable=feet)
  22. feet_entry.grid(column=2, row=1, sticky=(W, E))
  23.  
  24. Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
  25. Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)
  26.  
  27. Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
  28. Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
  29. Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)
  30.  
  31. for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
  32.  
  33. feet_entry.focus()
  34. root.bind('<Return>', calculate)
  35.  
  36. root.mainloop()

Incluso en la documentación te ofrecen un ejemplo. http://effbot.org/tkinterbook/entry.htm

Etiquetas: usar
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 01:23.