May-31-2017, 02:01 AM
(This post was last modified: May-31-2017, 02:01 AM by icabero0225.)
I'm writing a program to assist me in stock trading, and I wanted to make it have a nice GUI so my buddies can use it as well. I just started learning Tkinter yesterday, so my code is not perfect. Here's what I got:
from tkinter import * #Functions def buy(): datr = float(datrEntry.get()) dzd = float(dzdEntry.get()) dzp = float(dzpEntry.get()) szp = float(szpEntry.get()) szd = float(szdEntry.get()) wr = (datr * 0.02) sl = (dzd - wr) rsk = (dzp - sl) rwd = (rsk * 3) t1 = (dzp + rwd) t2 = szp global buyText, buyEntryText, buySlText, buyT1Text buyText=Label(root, text="Buy\n", fg="green") buyEntryText= Label(root, text="Entry: "+str(dzp)) buySlText= Label(root, text="Stop Loss: "+str(sl)) buyT1Text=Label(root, text="Target: "+str(t1)+"\n") buyText.grid(sticky=W) buyEntryText.grid(sticky=W) buySlText.grid(sticky=W) buyT1Text.grid(sticky=W) def sell(): exit() #I'm not done coding this part yet def clearScreen(): buyText.grid_forget() buyEntryText.grid_forget() buySlText.grid_forget() buyT1Text.grid_forget() #Window root = Tk() root.title("Trading Engine") menu = Menu(root) root.config(menu=menu) fileMenu = Menu(menu) menu.add_cascade(label="File", menu = fileMenu) fileMenu.add_command(label="Exit", command=exit) datrLabel=Label(root, text="Daily Average True Range") datrEntry = Entry(root) dzdLabel = Label(root, text="Demand Zone Distal") dzdEntry = Entry(root) dzpLabel=Label(root, text="Demand Zone Proximal") dzpEntry=Entry(root) szpLabel=Label(root, text="Supply Zone Proximal") szpEntry=Entry(root) szdLabel=Label(root, text="Supply Zone Distal") szdEntry=Entry(root) datrLabel.grid(row=0, column=0,sticky=E) datrEntry.grid(row=0, column=1) dzdLabel.grid(row=2, column=0,sticky=E) dzdEntry.grid(row=2, column=1) dzpLabel.grid(row=4, column=0,sticky=E) dzpEntry.grid(row=4, column=1) szpLabel.grid(row=6, column=0,sticky=E) szpEntry.grid(row=6, column=1) szdLabel.grid(row=8, column=0,sticky=E) szdEntry.grid(row=8, column=1) toolbar = Frame(root) toolbar.grid(sticky=W, padx=15, pady=10, columnspan=3) buyButton = Button(toolbar, text="Buy", command=buy, relief=RAISED, borderwidth=2, bg="green") sellButton = Button(toolbar, text="Sell", command=sell, relief=RAISED, borderwidth=2, bg="red") clearButton = Button(toolbar, text="Clear", command=clearScreen) buyButton.grid() sellButton.grid() clearButton.grid() root.geometry("500x500") root.mainloop()I know, I know, it's a mess. Basically, I'm trying to get the labels buyText, buyEntryText, buySlText, and buyT1Text that print after the buy() function completes to clear everytime I click the buy or sell button again. I don't really know how to explain this any better, so you can ask any questions to clarify if you want.