Python - Problema con suma, .get y cuadro de texto para numeros

 
Vista:

Problema con suma, .get y cuadro de texto para numeros

Publicado por Mateo (4 intervenciones) el 29/09/2017 00:11:39
Alguien sabe como puedo utilizar una caja de texto pero para que me muestre numeros , y colocar el resultado de una suma en el.. al hacerlo me genera error con el .get() y si elimino el .get() en la definicion de la variable el resultado no da.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from tkinter import *
 
ventana = tk.Tk()
ventana.title("Geometria y Cargas")
ventana.geometry("280x200")
ventana.configure(background="light gray")
lb1 = tk.Label(text="Total = ", background= "light gray").place(x=10,y=10)
lbl2 = tk.Label(text="Numero 1= ", background= "light gray").place(x=65,y=100)
lbl3 = tk.Label(text="Numero 2 = ", background= "light gray").place(x=65,y=120)
 
Var=tk.StringVar()
 
Total=tk.Entry(ventana,textvariable=Var,width= 6).place(x= 135,y= 10)
 
entrada1=tk.Entry(ventana,width= 10).place(x= 135,y= 100)
entrada2=tk.Entry(ventana,width= 10).place(x= 135,y= 120)
 
def suma():
 
	suma=int(entrada1.get()) + int(entrada2.get())
 
	return Var.set(suma)
 
 
btnAceptar=tk.Button(ventana,text="Sumar",width=8, command=suma).place(x=180, y=150)
 
ventana.mainloop()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Problema con suma, .get y cuadro de texto para numeros

Publicado por franco (1 intervención) el 16/11/2018 14:39:59
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from tkinter import *
import tkinter as tk
 
ventana = tk.Tk()
ventana.title("Geometria y Cargas")
ventana.geometry("280x200")
ventana.configure(background="light gray")
lb1 = tk.Label(text="Total = ", background= "light gray").place(x=10,y=10)
lbl2 = tk.Label(text="Numero 1= ", background= "light gray").place(x=65,y=100)
lbl3 = tk.Label(text="Numero 2 = ", background= "light gray").place(x=65,y=120)
 
Var=tk.StringVar()
 
Total=tk.Entry(ventana,textvariable=Var,width= 6)
Total.place(x= 135,y= 10)
 
entrada1=tk.Entry(ventana,width= 10)
entrada1.place(x= 135,y= 100)
 
entrada2=tk.Entry(ventana,width= 10)
entrada2.place(x= 135,y= 120)
 
def suma():
    uno = int(entrada1.get())
    dos = int(entrada2.get())
    suma= (uno + dos)
    return Var.set(suma)
 
 
btnAceptar=tk.Button(ventana,text="Sumar",width=8, command=suma).place(x=180, y=150)
 
ventana.mainloop()
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar