[Python] Python script using tkinterweb not allowing key binding [duplicate]

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    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()

    Continue reading...

Compartilhe esta Página