CEF-打开浏览器后,Tkinter中的输入按钮处于非活动状态



下面是我尝试运行的代码。我想打开浏览器,但仍然可以使用输入框。我正在使用线程,浏览器打开或加载正确。但是,输入框变为非活动状态。如何在浏览器打开时使用输入框。非常感谢您的帮助。

''

import tkinter as tk
from tkinter import messagebox
from cefpython3 import cefpython as cef
import threading
import sys

def test_thread(frame,link):
sys.excepthook = cef.ExceptHook
window_info = cef.WindowInfo(frame.winfo_id())
window_info.SetAsChild(frame.winfo_id(), rect)
cef.Initialize()
browser = cef.CreateBrowserSync(window_info, url=link)
root.after(1,activate_after_thread)
cef.MessageLoop()

def on_closing():
print('closing')
help(cef)
root.destroy()
def activate_after_thread():
entry.config(bg="blue")
pass
root = tk.Tk()
root.geometry('800x600')
root.protocol('WM_DELETE_WINDOW', on_closing)
frame = tk.Frame(root, bg='blue', height=200)
frame2 = tk.Frame(root, bg='white', height=200)
frame.pack(side='top', fill='x')
frame2.pack(side='top', fill='x')
tk.Button(frame2, text='Exit', command=on_closing).pack(side='left')
tk.Button(frame2, text='Show something',
command=lambda: messagebox.showinfo('TITLE', 'Shown something')).pack(side='right')
#
var = tk.StringVar()
entry = tk.Entry(frame2, width=70, textvariable=var)
entry.pack()
rect = [0, 0, 800, 200]
print('browser: ', rect[2], 'x', rect[3])
link = "https://www.google.com/"
thread = threading.Thread(target=test_thread, args=(frame,link,))
thread.start()
root.mainloop()

''

我让它工作起来了,我没有做错任何事情,只是CEF被嵌入到当前窗口中,所以,它实际上充当了两个独立的窗口。按下alt+tab,看看它会起作用,就像切换到其他应用程序一样,它会很好地工作,idk为什么输入框的事情会发生,按钮不会发生,所以你可以创建一个按钮来触发它创建一个输入框,这会使它起作用。祝你今天过得愉快!

最新更新