I am using Python 3.11.9 on windows OS.
I want to create button in tkinter which when pressed add text to entry i selected before clicking the button.
Here is my example code
from tkinter import *
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
frtop=self.winfo_toplevel() #Flexible Toplevel of the window
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
print("width="+str(screen_width)+", height="+str(screen_height))
max_windows_size=str(screen_width)+"x"+str(screen_height)
frtop.geometry(max_windows_size)
self.grid()
self.cash_frame = Frame(self)
self.cash_frame.grid(column =0, row =0, sticky='NSEW',columnspan=1)
self.cash_lbl = Label(self.cash_frame, text = "Cash:", font=('Arial',20,'bold'))
self.cash_lbl.grid(column =0, row =0)
self.cash_str_null = StringVar()
self.cash_str_null.set('')
self.cash = Entry(self.cash_frame, width=5,textvariable=self.cash_str_null, font=('Arial',26,'bold'))
self.cash.grid(column =1, row =0)
self.exchange_frame = Frame(self)
self.exchange_frame.grid(column =0, row =1, sticky='NSEW')
self.lbl_exchange = Label(self.exchange_frame, text = "exchange",font=('Arial',20,'bold'))
self.lbl_exchange.grid(column =0, row =0)
self.exchange_str_null = StringVar()
self.exchange_str_null.set('')
self.exchange_value = Entry(self.exchange_frame, width=5,textvariable=self.exchange_str_null,font=('Arial',20,'bold'))
self.exchange_value.grid(column =1, row =0)
self.add_one = Button(self, text = "1" , fg = "red", command=self.add_one_in_entry,font=('Arial',20,'bold'))
self.add_one.grid(column=0, row=2)
def add_one_in_entry(self):
pass
if __name__ == "__main__":
app = Application()
app.master.title("Sample application")
app.mainloop()
How can I do that ?
Thanks