Python GUI to accept user input in pop up

Clash Royale CLAN TAG#URR8PPP
Python GUI to accept user input in pop up
I am in the process of building a python GUI app. I got all my code working and functions interacting from the terminal, however I am struggling to get the initial user input working in tkinter. This initial user input drives the rest of my functions. How could I translate my code below to work in tkinter driven by buttons.
import pandas as pd
df = pd.DataFrame(columns=["Stock", "Holding"])
parts = int(input("Enter the number of Stocks you own: "))
for _ in range(parts):
dp = input("Enter Stock " )
st = input("Enter number of share you own " .format(dp))
df1 = pd.DataFrame(data=[[dp,st]],columns=["Stock", "Holding"])
df = pd.concat([df,df1], axis=0)
df.index = range(len(df.index))
print (df)
mylist = df['Stock'].tolist()
print (mylist)
2 Answers
2
Try this link: http://effbot.org/tkinterbook/tkinter-index.htm for help getting started. If you can think it, TKinter probably has a way to implement it. Start with a blank slate, try different things, get some buttons implemented and clickable, and go from there.
A button will have a "command" attached to it upon initialization, so this is where you can start to tie together the GUI and your actual code. Start with the button commands being "None" just so you can get a feel for things, and then figure out where you want to go from there.
It took me about a day to go from 0 TKinter knowledge to being able to teach others at work about it, so just scour the internet, google your questions, and if you need to, post more specific questions here. This question is too broad for more of an answer, but I hope you can at least use this as a starting point.
This should have been more of a comment. Link only answer are not considered long term useful as links break and thus can no longer provide benefit to the users.
– Mike - SMT
Aug 9 at 20:34
Here is a simple Tkinter example that you can use to ask the user how many stocks they have and then the stock name and quantity. Once you have answer all those questions it displays in the labels for each.
Let me know if you have any questions.
import tkinter as tk[![enter image description here][1]][1]
import tkinter.simpledialog as simpledialog
import pandas as pd
root = tk.Tk()
def do_stuff():
df = pd.DataFrame(columns=["Stock", "Holding"])
for _ in range(int(parts.get())):
dp = simpledialog.askstring("Data input window" , "Enter Stock " )
st = simpledialog.askstring("Data input window" , "Enter number of share you own " .format(dp))
df1 = pd.DataFrame(data=[[dp,st]],columns=["Stock", "Holding"])
df = pd.concat([df,df1], axis=0)
df.index = range(len(df.index))
mylist = df['Stock'].tolist()
lbl_df.config(text=df)
lbl_ml.config(text=mylist)
tk.Label(root, text="Enter the number of Stocks you own: ").grid(row=0, column=0)
parts = tk.Entry(root)
parts.grid(row=1, column=0)
tk.Button(root, text="Submit", command=do_stuff).grid(row=2, column=0)
lbl_df = tk.Label(root, text="")
lbl_df.grid(row=3, column=0)
lbl_ml = tk.Label(root, text="")
lbl_ml.grid(row=4, column=0)
root.mainloop()
End result will look something like this:

This is just a simple example but you can get far more detailed or cleaver with your application.
Thanks, I will experiment and see where i can take it
– hthomas
Aug 10 at 15:11
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Hi @hthomas, your question is quite broad, you should first start looking the web for some tutorial on how to use Tkinter (there's many of those) and then come back here with a more specific question. Good luck!
– toti08
Aug 9 at 19:41