Issue
A beginner here. I am using Tkinter to operate Selenium. Logs and other information are also partially displayed in Tkinter, but as I use it, the two windows are becoming cumbersome to handle. Please let me know if there is a way to combine them into one.
From my point of view I wrote a very long code in my history and I don't want to use a non-selenium browsing tool like I saw in my search if possible (I don't want to rewrite it from scratch).
For reference, the libraries used in my code are as follows:
from time import sleep
import sys
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import tkinter as tk
from tkinter import scrolledtext
from tkinter import ttk
from tkinter import *
import threading
import queue
import os
from datetime import datetime
import configparser
import errno
Thanks!
I tried: I have asked Chat GPT and searched this site and some, but I have not been able to find a way to merge Selenium and Tkinter windows together.
Solution
To be honest you cant embed any modern webbrower into tkinter window,there was a project that had chromium embed(not anymore) : source : cef python
REASON
to render to tkinter the browser must support rendering to a window id(if it supports that then you could render it by passing tkinter.winfo_id()
to the webbrowser).But as far as i know there arent any currently updated module or code that you can use to embed any webbrowser into tkinter.So you cant run chrome inside tkinter.
SUMMARY
- The only official webbrowser for tkinter was updated many years ago and it dosent even support modern html or js source : tkhtml
- The one project that was able to run chromium(chrome) inside tkinter hasnt been updated since 3 years and it dosent have support to newer python versions.source : cef python
- So since chromium(chrome) cant be embedded to tkinter,there's no way that you can use selenium chrome driver(window) inside of tkinter window.
I have done many research on this and the only way this could be possible is by using Gecko (and make selenium use Gecko(Firefox)) but its never straightforward you actually may need to compile Gecko and embed it and create your own api's to communicate with selenium.Also it will result in a large executable size.So use another gui instead of tkinter(cuz its very old to run modern browsers)
or you could make something like your own api :) like this videoplayer for tkinter(with sound) that wasnt actually possible using tkinter : tkinter videoplayer with sound
Also please upvote this answer if it helped you :)
Answered By - cool-guy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.