-3

In tkinter, how should I command a button to enter its text in the selected entry

import tkinter as tk
tk.Entry(master, width=20,columnspan=2).grid(row=0,column=0)
tk.Button(master,command=?)
Geno C
  • 1,401
  • 3
  • 11
  • 26

1 Answers1

0

My answer is based on this answer

import tkinter as tk

entry = tk.Entry(master, width=20,columnspan=2)
entry.grid(row=0,column=0)

def set_text(text):
    entry.delete(0,tk.END) # clear any previously entered text
    entry.insert(0,text) #insert new text
    return

text = 'hello' # text of button
tk.Button(master,text = text,command=lambda:set_text(text))