Home > Blockchain >  Taking input from Entry in Tkinter and using it in the back-end
Taking input from Entry in Tkinter and using it in the back-end

Time:06-30

I have created a code for plotting graphs using csv files and also a Python GUI using Tkinter which is a simple GUI for getting the input from the user and plotting graphs.

Ps. The input a date that is to be added in the back-end file to the file path of csv which is read and plotted.

Here's my code in short:

def backend():
    *importing libraries*
    root= Tk()
    inp = tkinter.StringVar()
    e = Entry(root, textvariable=inp)
    e.pack()
    s = inp.get()
    csv = glob.glob("path"   s   "*.csv")
    *rest of the code for plotting graph*
//frontend
*importing libraries*
from file import backend()
root= Tk()
inp = tkinter.StringVar()
e = Entry(root, textvariable=inp)
e.pack()
def submit():
   s = inp.get()
*rest of the frontend code*
    
    

This code is running without any error but plot is not getting plotted after entering the data in the Tkinter window and clicking the button for plotting graphs.

I also tried by importing the entry variable directly from front-end but it is showing circular input error. Please help if any ideas. Thank you

CodePudding user response:

You need to bind an action to make something happen. I bind the Return key (Enter key) to the 'Entry' widget and added a button. Both will call the 'backend' function:

def backend(event=None):
    s = inp.get()
    print(s)


root = Tk()
inp = StringVar()
e = Entry(root, textvariable=inp)
e.pack()
# Return key will call backend
e.bind('<Return>', backend)
# Button will call backend
b = Button(root, text='backend', command=backend)
b.pack()
root.mainloop()
  • Related