tkinter and input()

Pierre Bonville pierre.bonville49 at gmail.com
Tue Sep 29 09:48:31 EDT 2020


 Hello everybody,
I have a small problem with the method .quit() of tkinter. Below is a
sketch of a much larger program, which shows the problem. I would like to
run the main program but keeping the tk window on the screen until the end.
Presently, execution stops after the first "plot" instruction. I don't
understand why. The program runs fine if one replaces "quit" by "destroy",
but then the tk window disappears. Is there a solution?
Thanks in advance for any answer,
Regards,
P.Bonville

# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
from tkinter import *
def init():
    global vit
    def print_par():
        global vitt
        vitt = vit.get()
        print("velocity= ",vitt," cm/s")
        fen.quit()

    vit = ""
    fen = Tk()
    vit0 = StringVar()
    Label(fen, text = "velocity (cm/s): ").grid(row=0)
    vit = Entry(fen,text = vit0)
    vit0.set(7.)
    vit.grid(row=0, column=1)
    button = Button(fen, text='OK', command=print_par).grid(row=5,column=0)
    fen.mainloop()

    vit = float(vitt)

init()
print(vit)

x = np.arange(0,4*np.pi,0.1)
y = np.sin(x)

for i in range(0,10):
    plt.plot(x,y)
    plt.show()
    re = input("Hit RETURN to continue:")


More information about the Python-list mailing list