I have a simple script that uses tkinterweb to display a search result that is stored as html. When I try to bind the search function to the Enter key using the "button.bind('',function())" method, it executes the function immediately on mainloop and doesn't execute it when the Enter key is pressed. Is this a problem with tkinterweb? Minimum reproducible is below:
import tkinter
from tkinter import ttk
from tkinter import messagebox
import pickle
import tkinterweb
from tkinterweb import *
proj = tkinter.Tk()
proj.geometry("550x550")
proj.title("Offline Info Files")
proj.bind('<Escape>', quit)
def infosearch(Event=None):
target = "Search"
codesnip = "<h1>HELLO THERE!</h1>"
popup = tkinter.Toplevel()
popup.geometry("1100x700")
popup.title("Info " + str(target))
frame = HtmlFrame(popup)
frame.pack(fill="both",expand=True)
frame.load_html(codesnip)
Title = tkinter.Entry(bd=1, width = 20,font=("Courier New", 12), textvariable="infofile")
Title.pack()
searchbutton = tkinter.Button(text=" Search ", font=("Courier New",12), command = infosearch)
searchbutton.pack()
searchbutton.bind('<Return>',infosearch())
Title.focus_set()
proj.mainloop()
from tkinterweb import *if you're already usingimport tkinterweb- you can just prefixtkinterwebobjects like so:tkinterweb.HtmlFrame. You generally want to avoid "star imports" as best practice.commandoption of the button.searchbutton.bind('<Return>', infosearch).bind()similar tocommand=andafter()needs function's name without()- and it will later use()to execute this command. This name in function often is called"callback".