Is there a way to print it out where the text cursor is located instead of cmd?

114 Views Asked by At

I am creating a program using tkinter that words are stored in a button and the words are printed when the button is pressed.

I want the word to be printed where the text cursor is located(outside the program like a virtual keyboard), but when I made an exe file with pyinstaller, it was printed only in the cmd window.

I don't know if there's a way to use the print function to print it out where the text cursor is located instead of cmd, or if I should try a different approach, such as a module.

from tkinter import *

root = Tk()
root.title("TEST")
root.geometry("240x240")
root.resizable(False, False)

def test():
    print("test")

basic_test = Button(root, text="test", command=test)
basic_test.pack()

root.mainloop()
1

There are 1 best solutions below

1
Thorkel-dev On

You can add arguments to the function to print the desired text.

To do this use a lambda. It will look like this:

button = Button(root, text='test', command= lambda: test('test'))