Home > other >  How to click text to input or call a function in python
How to click text to input or call a function in python

Time:03-14

Is it possible to just click printed text, I know buttons are usable but it would be nice if I could use text or buttons that don't open a new window, I don't need to open links, just to make it call a function. I searched the internet but I'm not finding anything relevant, if you do please post the link.

CodePudding user response:

To clarify, I assume you are asking for a way to click on the displayed text in the GUI to call a function.

  • If so, you can simply store this displayed text and not display it, but rather create a button with a transparent background with the stored text as its label.

    Maybe something like this:
from tkinter import *

#Tab setup
win = Tk()
win.geometry("800x500")

#The text and button setup
displayText = "Hello World"
textButton=Button(win,text=displayText,width=20,height=2,command=FUNCTION_NAME_HERE).pack()

#Run tab
win.mainloop()

CodePudding user response:

Use span

<span onclick="doSomething()">Your Text</span>

function doSomething() {
   // do something
}
  • Related