Python Forum
[Tkinter] Using Tkinter to calculate while formula
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Using Tkinter to calculate while formula
#1
Hello all,

I'm trying to create a simple GUI interface with tkinter using a simple strokes calculator based on an user input. My simple code is below, but I cannot discover how to plot this on the tkinter interface. Could you guys help me on that?

from time import sleep

a = int(input('What is the total Drillstring SPM:'))
stroke_rate = a # strokes/min
stroke_sec = (round((stroke_rate / 60), 2))
stroke_count = 0
run = True

while run == True:
    stroke_count += stroke_sec
    print(str(stroke_count) +' STROKES')
    sleep(1)
And this was what I tried, but did not work:

from tkinter import *
from time import sleep
root = Tk()
root.title("Strokes Counter")
root.resizable(False, False)

def click_button():
    stroke_rate = ed1.get()
    stroke_count = 0
    run = True    
    while run == True:
        stroke_count += stroke_rate
        sleep(1)
        
    lb2 = Label(root, print(str(stroke_count) +' stk'))
    lb2.grid(row=3, column=0)


lb1 = Label(root, text="What is the SPM: ")
lb1.grid(row=0, column=0)

ed1 = Entry(root)
ed1.grid(row=0, column=1)

bt1 = Button(root, text="Confirm", command=click_button)
bt1.grid(row=2, column=0)

root.geometry("300x100")
root.mainloop()
Thanks in advance, guys!
Reply


Messages In This Thread
Using Tkinter to calculate while formula - by marlonsmachado - Sep-03-2022, 11:35 AM

Forum Jump:

User Panel Messages

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