0

Below is the code I am trying to run. I want to open a browser and still be able to use the entry box. I am using threading and the browser opens up or loads correctly. However the entry box becomes inactive. How can be able to use the entry box while the browser is opening. Would really appreciate any help.

'''

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

'''

1 Answers1

0

I got it working, I didn't do anything wrong, it's just that, CEF is being embedded in the current window, so, it's actually acting as two separate windows. press alt+tab and see it will work, like switch to some other application and it will work fine, idk why is happening with the entry box thing, it doesn't happen with buttons, so you can create a button that triggers it to create an entry box, that's going to make it work. Have a great day!

Abhay Gaur
  • 21
  • 7