Python Forum
how to show a value to the user? - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: how to show a value to the user? (/thread-2018.html)



how to show a value to the user? - elhetch - Feb-11-2017

i created the below code to do some math, i would like to know how to show the value after running the code to the user?


import math
from Tkinter import *
def circle_weight():
    area = math.pi*int(ent1.get())**2
    weight = area*int(ent2.get())
    print weight
    
master = Tk()
master.title("Disc Weight Calculator")
master.geometry("300x300")
master.wm_iconbitmap('steel-alloy.ico')

lbl1=Label(master,text="Radius",bg="cornsilk")
ent1=Entry(master)
lbl1.pack()
ent1.pack()
lbl2=Label(master,text="Thk")
ent2=Entry(master)
lbl2.pack()
ent2.pack()
btn=Button(master,text="Calculate",command=circle_weight)
btn.pack()

master.mainloop()



RE: how to show a value to the user? - metulburr - Feb-11-2017

create a label and use the textvariable to make it change on the fly of the button


RE: how to show a value to the user? - elhetch - Feb-11-2017

(Feb-11-2017, 12:19 AM)metulburr Wrote: create a label and use the textvariable to make it change on the fly of the button

mate ,i am totally new in coding, basically i dont understand what you just said, , what will be the shape of the code ?


RE: how to show a value to the user? - Yoriz - Feb-11-2017

The code will be of similar shape to what you have already but will be a little longer vertically.


RE: how to show a value to the user? - metulburr - Feb-11-2017

The link i showed you has a tutorial for label and the argument textvariable. 
import math
from Tkinter import *
def circle_weight():
    area = math.pi*int(ent1.get())**2
    weight = area*int(ent2.get())
    print weight
    v.set(weight)
     
master = Tk()
master.title("Disc Weight Calculator")
master.geometry("300x300")
#master.wm_iconbitmap('steel-alloy.ico')
v=IntVar()
output = Label(master, textvariable=v)
lbl1=Label(master,text="Radius",bg="cornsilk")
ent1=Entry(master)
lbl1.pack()
ent1.pack()
lbl2=Label(master,text="Thk")
ent2=Entry(master)
lbl2.pack()
ent2.pack()
btn=Button(master,text="Calculate",command=circle_weight)
btn.pack()
output.pack()
 
master.mainloop()
@Yoriz
LOL