pythontkinterpywebview

How can I log into a website within a tkinter gui using webview?


I wish to open a url in a tkinter gui. This works fine, however, when I click on the login icon it opens in an external browser. Am I able to log into the site and stay in the same tkinter gui? Thanks

# Import tkinter and webview libraries
from tkinter import *
import webview
  
# define an instance of tkinter
tk = Tk()
  
#  size of the window where we show our website
tk.geometry("800x800")
  
# Open website
webview.create_window('mapgenie', 'https://mapgenie.io/diablo-4/maps/sanctuary')
webview.start()

Solution

  • I tested your code by running another website and attempting to login; everything worked well, and the webpage also opened in the tkinter window.

    Try the following website if you have an account on it or else try instagram -

    from tkinter import *
    import webview
      
    # define an instance of tkinter
    tk = Tk()
      
    #  size of the window where we show our website
    tk.geometry("800x800")
      
    # Open website
    webview.create_window('HackerRank', 'https://www.hackerrank.com/')
    webview.start()
    

    I believe the problem with the login page opening in the browser at https://mapgenie.io/diablo-4/maps/sanctuary is due to the website's framework. You may try inspecting and seeing the HTML framework.

    Reason - As seen in the figure below, there is a 'href' (hypertext reference) included in the anchor tag, which opens the web browser.

    Mapgenie's Login Button Inspection

    But this is not the case with Hackerrank (Image for reference) -

    HackerRank's Login Button Inspection

    Hope it's clear now.