Python Forum
how to show a value to the user?
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how to show a value to the user?
#1
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()
Reply
#2
create a label and use the textvariable to make it change on the fly of the button
Recommended Tutorials:
Reply
#3
(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 ?
Reply
#4
The code will be of similar shape to what you have already but will be a little longer vertically.
Reply
#5
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
Recommended Tutorials:
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020