Ive made a sample program on how generally it looks like.. my goal is to have the Data Entry write permanently to the button so dat if I run the program again its update the current price.
from tkinter import*
import tkinter as tk
import tkinter.simpledialog
def changeP1(event):
btnT4=tk.Button(root,text='Updating...',width=10,bg='green')
btnT4.grid(in_=root,row=1,column=2)
btnT4.bind('<1>',changeP1)
askC1=tk.simpledialog.askfloat('Updating...','What is the current price?')
btnT4=tk.Button(root,text=('RM {:,.2f}'.format(askC1)),width=10)
btnT4.grid(in_=root,row=1,column=2)
btnT4.bind('<1>',changeP1)
def changeP2(event):
btnT4=tk.Button(root,text='Updating...',width=10,bg='green')
btnT4.grid(in_=root,row=2,column=2)
btnT4.bind('<1>',changeP2)
askC2=tk.simpledialog.askfloat('Updating...','What is the current price?')
btnT4=tk.Button(root,text=('RM {:,.2f}'.format(askC2)),width=10)
btnT4.grid(in_=root,row=2,column=2)
btnT4.bind('<1>',changeP2)
def changeP3(event):
btnT4=tk.Button(root,text='Updating...',width=10,bg='green')
btnT4.grid(in_=root,row=3,column=2)
btnT4.bind('<1>',changeP3)
askC3=tk.simpledialog.askfloat('Updating...','What is the current price?')
btnT4=tk.Button(root,text=('RM {:,.2f}'.format(askC3)),width=10)
btnT4.grid(in_=root,row=3,column=2)
btnT4.bind('<1>',changeP3)
root=Tk()
Title=['Item','Unit','Price']
Item=['Kopi O','Teh O','Teh Tarik']
Unit= '1 cup'
Price=[1,0.9,1.2]
cl=[0,1,2]
rw=[1,2,3]
for i in range(3):
btnT1=tk.Button(root,text=Title[i],width=10,bg='yellow')
btnT1.grid(in_=root,row=0,column=cl[i])
for x in range(3):
btnT2=tk.Button(root,text=Item[x],width=10)
btnT2.grid(in_=root,row=rw[x],column=0)
for y in range(3):
btnT3=tk.Button(root,text=Unit,width=10)
btnT3.grid(in_=root,row=rw[y],column=1)
for z in range(3):
btnT4=tk.Button(root,text=('RM {:,.2f}'.format(Price[z])),width=10)
btnT4.grid(in_=root,row=rw[z],column=2)
if z in range(0,1):
btnT4.bind('<1>',changeP1)
if z in range(1,2):
btnT4.bind('<1>',changeP2)
if z in range(2,3):
btnT4.bind('<1>',changeP3)
root.mainloop()
and if theres anyway to make this simpler..