Giter Club home page Giter Club logo

tkinterweb's Introduction

TkinterWeb

A fast and lightweight cross-platform webbrowser widget for Tkinter.

   

Overview

TkinterWeb offers bindings for the Tkhtml3 widget from http://tkhtml.tcl.tk/tkhtml.html, which enables loading HTML and CSS code into Tkinter applications.

All major operating systems running Python 2.6+ or Python 3+ are supported.

   

Usage

TkinterWeb provides:

TkinterWeb can be used in any Tkinter application. Here is an example:

from tkinterweb import HtmlFrame #import the HTML browser
try:
  import tkinter as tk #python3
except ImportError:
  import Tkinter as tk #python2

root = tk.Tk() #create the tkinter window
frame = HtmlFrame(root) #create the HTML browser
frame.load_website("http://tkhtml.tcl.tk/tkhtml.html") #load a website
frame.pack(fill="both", expand=True) #attach the HtmlFrame widget to the parent window
root.mainloop()

TkinterWeb

Some other tricks, such as handling page title changes, link clicks, and navigation key presses, can be found in the HtmlFrame documentation

   

Installation

To install TkinterWeb, simply type pip install tkinterweb in the command prompt or terminal. That's it.

   

Dependencies

In order to load webpages and show images, TkinterWeb requires the following packages:

  • Tkinter (which is automatically packaged with most Python installations)
  • PIL (can be installed via pip install pillow)
  • PIL.ImageTk (may be automatically installed with PIL on some systems, otherwise needs to be installed)

Pip will automatically install PIL when installing TkinterWeb.

   

API documentation

TkinterWeb ships with a few classes that make it quick and easy to use.

Documentation and additional information for these classes can be found in the corresponding API refrence pages:

   

FAQs

See https://github.com/Andereoo/TkinterWeb/blob/main/tkinterweb/docs/FAQ.md.

   

Webpage Compatability

HTML/CSS:

  • TkinterWeb supports HTML 4.01 and CSS 2.1. A full list of supported CSS declarations can be found at http://tkhtml.tcl.tk/support.html.
  • Most CSS Pseudo-elements, such as :hover and :active are also supported.

JavaScript:

  • Javascript is not supported at the moment.

Images:

  • TkinterWeb supports nearly 50 different image types through PIL. Scalable Vector Graphic support is not as straightforward, though. In order to load SVG images:
    • PyCairo or PyGObject must be installed.
    • Either Rsvg, PyGObject, or CairoSVG must also be installed.
  • Without these packages, TkinterWeb will still function properly, but SVG files will not be shown.

   

Contributing

TkinterWeb happily accepts contributions.

The best way to contribute to this project is to go to the issues tab and report bugs or submit a feature request. This helps TkinterWeb become more stable and full-featured. Please check the FAQs and closed bugs before submitting a bug report to see if your question as already been answered.

   

Credits

TkinterWeb is powered by the Tkhtml project.

Thanks to the TkinterHtml package for providing the bindings which this project is based on.

Thanks to the BRL-CAD project for providing modifications for Tkhtml on 64-bit Windows platforms.

Thanks to Google Fonts for providing the font used for generating alternate text when images fail to load.

A special thanks to everyone else who helped this project by reporting bugs and providing suggestions!

tkinterweb's People

Contributors

andereoo avatar jaedsonpys avatar nickzoic avatar sau1707 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

tkinterweb's Issues

Charset ?

Hello,

Very impressed by this package, is there any way to manage the charset ?

My content is in french, and there are problems with accentuated chars for example...
image

Note that I include the <meta charset="utf-8">.

Thanks a lot !

Internal hrefs not working in Linux

I'm using tkinterweb to display a help file in my app. The help has a table of contents, containing internal hrefs:

<a href="#penguins">Penguins are great!</a>

and farther on

<h2 id="penguins">Penguins</h2>

In Windows this works as expected: clicking the link jumps to the relevant section. In Linux, I get "Oops! The document could not be found." I tried using name="penguins" instead of "id" but no joy there. Any idea what's going wrong?

UPDATE: the following technique kind of achieves the intended effect:

<a href="./this_document.html#penguins">Penguins are great!</a>

I assume it just reloads the current document at the specified ID, but ideally it should be possible to do a jump without reloading.

Thanks!

Search on the page

Hello!

I have a question about HtmlFrame.
I need to create a function like "search on the page".
Can I highlight all text that matches user input?

Local Images

HtmlLabel doesn't work with local images, it renders and sets the size but its white. I've checked the image path and that the image isn't empty.

images = HtmlLabel(
        root, text="<img src='/stickers/a.jpeg' width='50' height='50'/>"
    ).grid(row=3, column=0, columnspan=2)

imagen

RPI install - "bad marshal data" - pip3 install tkinterweb

Trying to install on a raspberry pi zero running 'Lite' but with openbox and lightdm. I also had this issue when trying to install on a Mac.

This may be an issue with distutils??

pi@raspberrypi:~ $ pip3 install tkinterweb Traceback (most recent call last): File "/usr/bin/pip3", line 9, in <module> from pip._internal import main File "/usr/lib/python3/dist-packages/pip/_internal/__init__.py", line 40, in <module> from pip._internal.cli.autocompletion import autocomplete File "/usr/lib/python3/dist-packages/pip/_internal/cli/autocompletion.py", line 8, in <module> from pip._internal.cli.main_parser import create_main_parser File "/usr/lib/python3/dist-packages/pip/_internal/cli/main_parser.py", line 8, in <module> from pip._internal.cli import cmdoptions File "/usr/lib/python3/dist-packages/pip/_internal/cli/cmdoptions.py", line 17, in <module> from pip._internal.locations import USER_CACHE_DIR, src_prefix File "/usr/lib/python3/dist-packages/pip/_internal/locations.py", line 11, in <module> from distutils.command.install import SCHEME_KEYS # type: ignore File "/usr/lib/python3.7/distutils/command/install.py", line 9, in <module> from distutils.core import Command File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 677, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 724, in exec_module File "<frozen importlib._bootstrap_external>", line 857, in get_code File "<frozen importlib._bootstrap_external>", line 525, in _compile_bytecode ValueError: bad marshal data (unknown type code)

Appending/Adding Additional HTML to a HTML Table Row

I'm trying to figure out a way to append additional rows to a html table without having to keep reloading the page without using 'load_html' to keep reloading the document and slowing down the browser while adding new table row data.

I see that there is the option to add additional html to the document without reloading it by using 'add_html', but how would I keep appending new rows to a html table?

For example, here's what my table rows look like:

<html>
	<table>
		<tr>
		      <th>#</h1><th>Heading 1</h1><th>Heading 2</h1><th>Heading 3</h1>
		</tr>
		<tr>
		      <td>1</td><td>DATA 1</td><td>DATA 1</td><td>DATA 1</td>
		</tr>
		**<!--APPEND/ADD-NEW-ROW-HERE!-->**
	</table>
</html>

Is there a way to quickly append another table row without constantly reloading the whole document? Is there a way just to manipulate the '<tr>' element so that I don't have to keep reloading the whole document?

I would like to click a Tkinter button, then it would append another row to the html table. Just trying to figure out which way it would be best to do so. I've tried replacing a 'html' variable where it says '', but it seems as though I'd have to keep reloading the document in order to replace the html variable that I'm using to load my html.

I'd appreciate the ideas. Thanks.

HtmlFrame Error

Hello, i used this code:
from tkinter import * from tkinterweb import HtmlFrame root = Tk() frame = HtmlFrame(root) frame.load_website("https://google.de") frame.pack(fill="both", expand=True) root.mainloop()

And this is my Exeption:
Traceback (most recent call last): File "C:\Users\Robin\atomProjects\python\TkWebWin\main.py", line 4, in <module> frame = HtmlFrame(root) File "C:\Users\Robin\AppData\Local\Programs\Python\Python38\Lib\site-packages\tkinterweb\html_frame.py", line 57, in __init__ html = self.html = TkinterWeb(self, message_func, fontscale=float(fontscale), zoom=float(zoom)) File "C:\Users\Robin\AppData\Local\Programs\Python\Python38\Lib\site-packages\tkinterweb\tkhtml_bindings.py", line 116, in __init__ load_tkhtml(master, get_tkhtml_folder()) File "C:\Users\Robin\AppData\Local\Programs\Python\Python38\Lib\site-packages\tkinterweb\tkhtml_bindings.py", line 64, in load_tkhtml master.tk.eval("package require Tkhtml") _tkinter.TclError: couldn't load library "C:/Users/Robin/AppData/Local/Programs/Python/Python38/Lib/site-packages/tkinterweb/tkhtml/Windows/64-bit/Tkhtml/Tkhtml30.dll": No error

I use Python 3.8.2 and pip 21.0.1 and HtmlFrame latest

If any infomation is missing, please answer down here

HtmlFrame error on m1 macbook pro: incompatible architecture, and missing files

Source code snippet:

# gui2.py
import tkinter as tk
from tkinterweb import HtmlFrame

class GUI:
    def __init__(self) -> None:
        self.root = tk.Tk()
        self.root.geometry("815x416")

        self.info_html = HtmlFrame(self.root, width=1, height=1, horizontal_scrollbar="auto",
                                   messages_enabled=False)
        self.info_html.grid(row=0, column=0)

        self.root.mainloop()

if __name__ == "__main__":
    GUI()

Error:

$ python gui2.py
Traceback (most recent call last):
  File "/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/bindings.py", line 82, in __init__
    load_tkhtml(master, folder)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/utilities.py", line 671, in load_tkhtml
    master.tk.eval("package require Tkhtml")
_tkinter.TclError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/tkhtml/Darwin/64-bit/Tkhtml30.dylib, 0x0006): tried: '/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/tkhtml/Darwin/64-bit/Tkhtml30.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/Tkhtml30.dylib' (no such file), '/usr/lib/Tkhtml30.dylib' (no such file)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/cuteufo/Projects/gui2.py", line 17, in <module>
    tradematch_GUI()
  File "/Users/cuteufo/Projects/gui2.py", line 9, in __init__
    self.info_html = HtmlFrame(self.root, width=1, height=1, horizontal_scrollbar="auto",
  File "/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/htmlwidgets.py", line 30, in __init__
    self.html = html = TkinterWeb(self, message_func, HtmlFrame)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/bindings.py", line 85, in __init__
    load_tkhtml(master, folder, force=True)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/utilities.py", line 671, in load_tkhtml
    master.tk.eval("package require Tkhtml")
_tkinter.TclError: dlopen(/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/tkhtml/Darwin/64-bit/Tkhtml30.dylib, 0x0006): tried: '/opt/homebrew/Caskroom/miniforge/base/envs/tf/lib/python3.9/site-packages/tkinterweb/tkhtml/Darwin/64-bit/Tkhtml30.dylib' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')), '/usr/local/lib/Tkhtml30.dylib' (no such file), '/usr/lib/Tkhtml30.dylib' (no such file)

Environment:

miniforge3 arm64
Python 3.9.7
tkinterweb 3.10.7
MacOS 12.1 Monterey on MacBook Pro M1 Max

Other notes:

1. same code can be run without errors if I switch to anaconda packaged Python 3.8.5 (Intel) environment
2. same errors when running in either terminal command line or PyCharm, as long as with miniforge Python (arm64)

“ModuleNotFoundError: No module named 'bindings'” on compiling with py2app

I've been compiling some apps with MacOS using Py2app, so far so good, but i've been having this error when compiling applications that contains the tkinterweb module, I'm not really sure what is causing this.

Error on executing the application:
Traceback (most recent call last): File "MyApp.py", line 40, in <module> File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module File "tkinterweb\__init__.py", line 30, in <module> ModuleNotFoundError: No module named 'bindings' [4712] Failed to execute script MyApp

Thanks in advance!

[Feature request] Rigth click on link

The feature
To be able to right click on hypertext link, and trigger a different action.

Use case
Be able to emulate the behavior "open in a new tab" or display a drop down menu, or whatever else.

Possible implementation
Add a method HtmlFrame.on_link_right_click(callback), triggered on right click.
AFAIK, binding stuff on ButtonRelease-3 should do it.

Also
Same idea with wheel click, and by extension all the button that Tkinter is aware of ?

Also again
To display a drop down menu "Browers-like style", I found this article that seems to be a good way to go. I don't what you want to do with it, but I'm leaving it here :)
https://www.geeksforgeeks.org/right-click-menu-using-tkinter/

/32-bit/Tkhtml30.so: cannot open shared object file: No such file or directory

Trying to install on a raspberry pi zero running 'Lite'
but with openbox and lightdm. This is with the latest Bullseye distribution.

I added some try - except code to find some issues and ran into this one. I see the file in the directory so it doesn't appear to be that.

/home/pi/.local/lib/python3.9/site-packages/tkinterweb/tkhtml/Linux/32-bit/Tkhtml30.so": /home/pi/.local/lib/python3.9/site-packages/tkinterweb/tkhtml/Linux/32-bit/Tkhtml30.so: cannot open shared object file: No such file or directory

It took a bit of snooping but I also found another earlier issue. I had to install libopenjp2-7. I was getting a non-descriptive import error.

Tkinter app crashes when I switch to the tab with HtmlFrame

Basically, when HtmlFrame is placed in a frame of a Notebook and you switch to that frame/tab right after the program starts, program crashes. I encountered this problem while adding HtmlFrame to Help & About tab of my program, and to make sure the problem is about the library and not my code, I've simplified the code:

from tkinter import *
from tkinter.ttk import *

from tkinterweb import HtmlFrame
from markdown import markdown
from requests import get

root = Tk()

notebook = Notebook(root, height=400, width=400)

frame1 = Frame(notebook)
frame2 = Frame(notebook)
frame3 = Frame(notebook)

notebook.add(frame1, text="Frame 1")
notebook.add(frame2, text="Frame 2")
notebook.add(frame3, text="HtmlFrame")

request = get("https://raw.githubusercontent.com/Yilmaz4/Encrypt-n-Decrypt/main/README.md").text
HTML = markdown(request)
readmePage = HtmlFrame(frame3, messages_enabled=False, vertical_scrollbar=True)
readmePage.load_html(HTML)
readmePage.pack(fill=BOTH, expand=True)

label1 = Label(frame1, text="This is the first frame, switch to the third frame\nto crash the program", justify=CENTER)
label1.place(relx=0.5, rely=0.5, anchor=CENTER)

label2 = Label(frame2, text="This is the second frame, as you switched to this\nframe before the third frame, program will no longer crash.", justify=CENTER)
label2.place(relx=0.5, rely=0.5, anchor=CENTER)

notebook.pack(fill=BOTH, expand=True)

root.mainloop()

Note: you can install the markdown package with this command: pip install markdown

When you run the code, click on "HtmlFrame" tab. The program will crash. However, if you click on another tab than the tab with HtmlFrame, and then switch to the tab with HtmlFrame, the program doesn't crash.

I'm on Windows 11 build 22000.469 (21H2)

HtmlLabel does not handle background color

Here is the HTML I'm trying to render using HtmlLabel... It seems to work except the "background: #aa9cfc;" colors don't display. You have to edit the post to see the html

Albert Einstein PERSON was born in Ulm,[7] in the Kingdom of Württemberg GPE in the German Empire GPE , on 14 March 1879 DATE into a family of secular Ashkenazi NORP Jews.

The website window is not opening

Hi ,

I am using python 3.8 . the below code i am using , the site is not loading

from tkinter import * 
from tkinterweb import HtmlFrame 

root = Tk() 
frame = HtmlFrame(root) 
frame.load_website("https://www.dummies.com/web-design-development/site-development/a-sample-web-page-in-html/") 
frame.pack(fill="both", expand=True) 
root.mainloop()

I got message like

UserNotification: Fetching Tkhtml3 for 64-bit Windows with Python 3.8.7.   
Tkhtml found in C:\Users\User0\python\Python38\Lib\site-packages\tkinterweb\tkhtml\Windows\64-bit.

after that the script execution stopped and no window is opening. is there any thing wrong that i am doing.

Thanks
Swagat

Vertical expanding/centering?

I'm no expert of HTML/CSS but I'm trying to make a div and center it in the screen filling 80% of the space horizontally and vertically.

This is a simplified demo of what I'm trying to obtain:

import tkinter as tk
from tkinterweb import HtmlFrame

html = \
"""
<!doctype html>
<html>
<body>
    <div class="center-red">
    TEST
    </div>
</body>
</html>
<style>
body {
    width: 100vw;
    height: 100vh;
}
.center-red {
    width: 80%;
    height: 80%;
    margin: auto;
    padding: 10px 10px;
    background-color: red;
    font-size: 100px;
    color: white;
}
</style>
"""


root = tk.Tk()
root.title("TEST")

root.geometry("%dx%d+%d+%d" % (800, 600, 100, 100))

html_frame = HtmlFrame(root, messages_enabled=False)
html_frame.pack(fill="both", expand=True)

html_frame.load_html(html)

root.mainloop()

And this is the output:

Screenshot (69)

Why is the div not expanding vertically? I tried to set a fixed height to body and the div expands correctly, but by setting body with height: 100vh or height: 100% it doesn't work. It's like it fails to get the window height to expand the body (?). I tried the same in Chrome and it works correctly.

Also, since I'm here, how am I supposed to center the div vertically the same way it happens horizontally with margin: auto?

Input fields

Hi again!
When opening pypi.org with htmlframe main search field is white and font color is also white.
Is it possible to change font color if input field is white?

Linux 32-bit - libopenjp2-7 is required but not installed - ModuleNotFoundError

When installing on a Raspberry Pi Zero running Raspberry Pi Os Lite (bullseye) with Openbox and LightDM installed...
On first use of tkinterweb I encountered a ModuleNotFoundError. I tweaked the tkinterweb constructor file (init.py) to get a bit more detail about the error and found the issue was (at least initially) occurring in the bindings.py file.

sudo apt install libopenjp2-7 fixed the issue. So it seems that tkinterweb depends on this but does not check for it when being installed.

Frame.on_link_click method doesn't work!

Hi again, I am trying to use the on_link_click method to capture the link clicks, and I designed the function to load the url when called, but it's not working as I excepted!
It just prints out "A link to blahblahblah has been clicked" and nothing happens then.
this is my function handling the url click. (Never mind the nonlocals and the vars, this is straight from my program.
def addToList(url): nonlocal searches nonlocal searchNo searches.append(str(url)) searchNo += 1 text.delete() text.insert(0, url) frame.load_url(url)

as you can clearly, see, in the function called by the on_link_click method, I load a url in the frame, but, the output is this!

image

background ? width and height ?

Hi again,

I continue my tests, and there is some stuff that I don't understand.

In the documentation, you say that HtmlFrame can take Frame arguments. I tried to set up background, width, and height. There is no error but the arguments seem to be not used (remove vertical scroll and message is OK).

For example, in a grid, the Frame takes a huge size.

Is there any way to scale the Frame to the content? (for the background, I will injet CSS)

Can't submit some forms

I have checked google and badssl forms.

import tkinter as tk
import tkinterweb as tw
import tkinter.messagebox as msb
root = tk.Tk()
frame = tw.HtmlFrame(root)
frame.on_form_submit(lambda *_: msb.showinfo("Form", "Form"))
frame.pack()
frame.load_website('http://very.badssl.com')
root.mainloop()

If form works the app will show a message box

google (message)
badssl (no message)

OS:
macOS Catalina 64-bit (python 3.9)
Windows 7 32-bit (python 3.7)

PS: sorry for my english

Crash on windows 32-bit

Hi!

my app crashes exactly like in issue #1 ,

is it because pip missing Tkhtml.dll?

I hope you will fix it asap!

Is there any "dark mode" for the frame?

Like many apps now, dark mode is essentially everywhere. Is there any way to implement a forced dark mode for websites through your HTMLFrame widget in any way?
PS: I saw your HTMLFrame documentation too, no mentions about themes at all, so I ask this question.

And also, good initiative too! In spite of this being a "lightweight" web viewer, I am actually trying to create a full blown browser in python with this! Keep going with this bro :)

A question

Hello!
I need to get coords (x,y) of some nodes in my app and I have their names e.g. ::tkhtml::node0.
Is it possible to get node coords by name?? if yes, can you tell me how

Tkinter/Tkhtml bug?

Hello!
When HtmlFrame loads a website that contains emojis HtmlFrame and Tkinter are becoming very blurry and laggy.
Please fix this issue ;)
img

Enhancement

Hello!
I have found a mention of iframe in TkinterWeb's DEFAULT_STYLE and I have an idea how to render iframe.
Maybe you can replace <iframe src="http://google.com" style="xxx"></iframe> with <div widgetid="small_htmlframe_in_main_htmlframe" style="xxx"></div>.
small_htmlframe_in_main_htmlframe will load a website that is in src attribute of iframe.
I hope it was useful.

webview

web_frame = tkw.WebView(window)

is there any alternate WebView function because it is not working

Javascript support

Hello again!
I know that Hv3 browser is using SEE library for JS rendering .
Maybe you can connect one of JS libs to TkinterWeb using ctypes.
I know some libs like SpiderMonkey, KJS, WEBKIT

Sliders in control aren't rendered

When adding a slider input control, it only displays it as a Text box

        <form action="index.html" method="POST">
            <div class="slidercontainer">
                <label for="wholeNotesWeight">Whole Notes</label>
                <input type="range" min="-1" max="1" value="0" step="0.0125" class="slider"
                       name="wholeNotesWeight" id="wholeNotesWeight">
            </div>
           <!-- More content -->
       </form>

image

I really like being able to use TKinterWeb in Reaper, and I do appreciate your work in this!

SSL CERTIFICATE_VERIFY_FAILED

Hello ! :)

Source code snippet :

import tkinter as tk
from tkinterweb import HtmlFrame #import the HTML browser

root = tk.Tk() #create the tkinter window
frame = HtmlFrame(root) #create the HTML browser
frame.load_website("https://www.google.com") #load a website
frame.pack(fill="both", expand=True) #attach the HtmlFrame widget to the parent window
root.mainloop()

Error :

An error has been encountered while loading https://www.google.com: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1129)>.

Environement :

macOS Catalina 
python 3.9.10
tkinterweb 3.10

Maybe you should use the ssl._create_unverified_context() from ssl package.
For example, your file utilities.py becomes(start at line 628):

un_verified_context = ssl._create_unverified_context()
if data and (method == "POST"):
      req = urlopen(Request(url, data, headers=HEADER), context=un_verified_context)
else:
      req = urlopen(Request(url, headers=HEADER), context=un_verified_context) 

I'm not sure that is the best solution but it should works! 👍

ModuleNotFoundError: No module named 'bindings' error after I compile my code

Hello, I'm making a GUI program with your TkinterWeb library. Code normally works without any problems but when I convert it to a *.exe file with pyinstaller and run it, it gives me this error:

Traceback (most recent call last):
  File "MyApp.py", line 40, in <module>
  File "PyInstaller\loader\pyimod03_importers.py", line 540, in exec_module
  File "tkinterweb\__init__.py", line 30, in <module>
ModuleNotFoundError: No module named 'bindings'
[4712] Failed to execute script MyApp

But I already have bindings library installed.
I was imported tkinterweb library by from tkinterweb import HtmlFrame in line 40 of my code. Can anyone help me?

Can't open local file

Trying to open a local file (url starting with file://localhost/...) doesn't work as http:// is added automatically.

How can I resize HtmlFrame widget?

I cannot resize it when I want to use place function to place HtmlFrame into somewhere in tkinter frame. Can you show me an example for resizing HtmlFrame when I place it with place function?

By the way this is my code:

update = Tk()
update.resizable(height=False, width=False)
update.attributes("-fullscreen", False)
update.geometry("600x200")
update.maxsize("600","200")
update.minsize("600","200")
HTML = #This is my html, never mind it.
frame = HtmlFrame(update)
frame.load_html(HTML)
frame.enable_caches(True)
frame.enable_objects(True)
frame.enable_forms(True)
frame.set_zoom(1)
frame.enable_images(True)
frame.place(?) #What should I do here?

Tkinter GUI crash on implementatin of HTMLFrame (Win10, python 3.8, PyCharm 2021.1.3)

I have implemented a Tkinterweb (3.9) call (HTMLFrame) inside of a ttk Notebook "Tab". The program is stable until I select the tab with the call where is exits/crashes with the exit code: -1073741819 (0xC0000005). This appears to be a buffer overflow/access violation problem?

Here is the code snippet with the call:

helpFrame = tk.Toplevel()
helpFrame.geometry("700x800")
helpFrame.title("Help Pages")

tabControl1= ttk.Notebook(helpFrame)
introTab = ttk.Frame(tabControl1)
mainHelpTab = ttk.Frame(tabControl1)
setHelpTab = ttk.Frame(tabControl1)
QApTab = ttk.Frame(tabControl1)
tabControl1.add(introTab, text='Introduction')
tabControl1.add(mainHelpTab, text='Main Help')
tabControl1.add(QApTab, text='QATrack+ Interface Help')
tabControl1.add(setHelpTab, text='Settings Help')
tabControl1.pack(expand=1, fill="both")

QApHtml_file = open(resource_path('QATrack+Interface.html'))
QApText = QApHtml_file.read()
QApHtml_file.close()
QApsubFrame = HtmlFrame(QApTab)
QApsubFrame.load_html(QApText)
QApsubFrame.pack(fill="both", expand=1)

The file it opens to grab the HTML changes, but I have simple HTML to HTML that includes tables and a <style></style> section. For all HTML code it will display for about 2 seconds and then exits with the above exit code.

This is also the same problem I am having with HTMlLabel (given that Label is a subclass of Frame, it appears the issue is with something in the HTMLFrame class? Or is this more fundamental with the dll, or selection of dll? I notice there is a folder with tkhtml, with Darwin, Linux, Windows, and a 32-bit, 64-bit options, maybe it is using the 32bit instead of the 64 bit?

Further investigation shows it is a dll, but not in this module. I would love to move this to a discussion forum, instead of listing as an issue, since it seems to be an issue, but not necessarily with the package. Full error from Event Viewer in Win10 gives:

Faulting application name: python.exe, version: 3.8.1150.1013, time stamp: 0x5dfab277
Faulting module name: tcl86t.dll, version: 8.6.2.9, time stamp: 0x5c12d592
Exception code: 0xc0000005
Fault offset: 0x00000000000fc633
Faulting process id: 0x7f4
Faulting application start time: 0x01d779ccb91ee152
Faulting application path: C:\Users\user\AppData\Local\Programs\Python\Python38\python.exe
Faulting module path: C:\Users\user\AppData\Local\Programs\Python\Python38\DLLs\tcl86t.dll
Report Id: 828419ce-7046-4d6c-a266-3ec839124afb
Faulting package full name:
Faulting package-relative application ID:

So an issue with a call to the tcl86t.dll. As a note I will attempt to update to Python 3.9 (with new(?) tcl dll) and see if this helps with the issue. Potentially a collision with 86 vs 64 dll file versions?

Multiple <br> tags not working together.

As the title says, multiple
tags aren't recognized individually but just as one of them. Im working with a mail template system and I'm using tkinterweb to make a little previsualization of that mail template;
06
Maybe I'm doing something wrong but the html code works perfectly on it's own.

Login problem to facebook

I tried to login facebook, I entered my information but nothing happened I did not receive any errors.

tkinterweb.HtmlFrame's on_form_submit function is not getting called on all submit buttons in different forms of HTML

HtmlFrame.on_form_submit is not functioning properly. In the example the HTML consist of two form having individual submit button. First form submit button's on_form_submit is triggering but another submit button's on_form_submit is not triggering.

from tkinterweb import HtmlFrame #import the HtmlFrame widget
try:
  import tkinter as tk #python3
except ImportError:
  import Tkinter as tk #python2
root = tk.Tk() #create the Tkinter window


def on_form_submit(url, data, method):
    try:
        print(url, data, method)
    except Exception as error:
        print (error)

user_html = """
                    <html>
                        <table>
                            <tr>
                                <form action="value.test" name="one" id="one" method="GET">
                                    <td>Site1<a href="test.html"></a><input type="hidden" name="myhidden1" value="site1"></td>
                                    <td><input type="submit" value="Open in Browser"></td>
                                </form>
                            </tr>
                            <tr>
                                <form action="value.test" name="two" id="two" method="GET">
                                    <td>site2<a href="test1.html"></a><input type="hidden" name="myhidden2" value="site2"></td>
                                    <td><input type="submit" value="Open in Browser"></td>
                                </form>
                            </tr>


                        </table>
                        
                        </ol>    
                        </div>                   
                    </html>
                """


### The important part: create the html widget and attach it to the window
myhtmlframe = HtmlFrame(root) #create HTML browser
myhtmlframe.load_html(user_html) #Load some HTML code
myhtmlframe.pack(fill="both", expand=True) #attach the HtmlFrame widget to the parent window
myhtmlframe.on_form_submit(on_form_submit)

root.mainloop()

Using base64 images

I'm working on a project that would require me to display base 64 images, loaded straight from the encoded data with no external files involved. I can generate the html and open it in another browser no problem, but attempting it on the htmlFrame object always yelds an error message. Is the format not supported?

The HTML tag that generates the error is:
<img src="data:image/png;charset=utf-8;base64,{banner_img}">
where {banner_img} is the encoded data.

Also, the error reads: "[base 64 data] could not be shown because it is corrupt or is not supported yet."

Error unknown option "-drawcleanupcrashcmd" on simple example

Hello,

The issue
When running a minimal example of tkinterweb, I run into an issue during loading

To reproduce
Run python3 -m tkinterweb.__init__
The console says :

Starting TkinterWeb for 64-bit Linux with Python 3.9.2.

Traceback (most recent call last):
  File "/home/yann/.local/lib/python3.9/site-packages/tkinterweb/bindings.py", line 85, in __init__
    tk.Widget.__init__(self, master, "html", cfg, kwargs)
  File "/usr/lib/python3.9/tkinter/__init__.py", line 2572, in __init__
    self.tk.call(
_tkinter.TclError: unknown option "-drawcleanupcrashcmd"

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.9/runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/yann/.local/lib/python3.9/site-packages/tkinterweb/__init__.py", line 86, in <module>
    Demo()
  File "/home/yann/.local/lib/python3.9/site-packages/tkinterweb/__init__.py", line 73, in __init__
    frame = HtmlFrame(root)
  File "/home/yann/.local/lib/python3.9/site-packages/tkinterweb/htmlwidgets.py", line 30, in __init__
    self.html = html = TkinterWeb(self, message_func, HtmlFrame)
  File "/home/yann/.local/lib/python3.9/site-packages/tkinterweb/bindings.py", line 88, in __init__
    tk.Widget.__init__(self, master, "html", cfg, kwargs)
  File "/usr/lib/python3.9/tkinter/__init__.py", line 2572, in __init__
    self.tk.call(
_tkinter.TclError: unknown option "-drawcleanupcrashcmd"

Current solution
I'm manually removing the "drawcleanupcrashcmd" from kwarg, by simply removing lines 77 to 80 of the file binding.py

        # catch htmldrawcleanup crashes on supported platforms
        if (platform.system() == "Windows") or (platform.system() == "Linux" and sys.maxsize > 2**32):
            if "drawcleanupcrashcmd" not in kwargs:
                kwargs["drawcleanupcrashcmd"] = master.register(self.on_drawcleanupcrash)

System
Debian 11 64 bits, up to date.

Thanks for any tips,
And I can't find any references online about drawcleanupcrashcmd or on_drawcleanupcrash :/ Where did you discovered it ?

PS : good job, btw, I'm building a simple GUI and it's very usable 👍

Cannot load map file that stored as html file

I try to make map rendered to tkinter, which that file, created by folium module.
I already tested to open the map file in browser, the file is fine...

now I want the same with tkinter.

from tkinterweb import HtmlFrame,HtmlLabel
from tkinter import Tk

file = 'map.html'

root = Tk()
root.title('Map')
root.geometry('1400x700')
frame = HtmlFrame(root)
frame.load_file('file:///'+file)
frame.pack()

root.mainloop()

the result just white blank frame, the preview like this:

tkinterweb

the debug process said:

Starting TkinterWeb for 64-bit Windows with Python 3.8.4.

Tkhtml3 successfully loaded from C:\Python\Lib\site-packages\tkinterweb\tkhtml\Windows\64-bit.

Welcome to TkinterWeb 3.10! 
https://github.com/Andereoo/TkinterWeb

Debugging messages are enabled. 
Use the parameter `messages_enabled = False` when calling HtmlFrame() to disable these messages.

Connecting to .

Loading stylesheet from https://cdn.jsdelivr.net/npm/[email protected]/dist/leaflet.css.

Loading stylesheet from https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css.

Loading stylesheet from https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css.

Loading stylesheet from https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css.

Loading stylesheet from https://cdnjs.cloudflare.com/ajax/libs/Leaflet.awesome-markers/2.0.2/leaflet.awesome-markers.css.

Loading stylesheet from https://rawcdn.githack.com/python-visualization/folium/master/folium/templates/leaflet.awesome.rotat....

Loading <style> element.

Loading <style> element.

Loading <style> element.

did I miss something?

Segmentation fault: 11, Kernel Crash (Occasionally Worked) MacOS ARM64

Hello,

Just wanted to see if this project was tested on MacOS with arm architecture? Even the simple demo only occasionally works (and quite randomly) for me, so just wanted to see if this was the problem or if it was something else. I get a "Segmentation fault: 11" error. Edited: I tried on Python version 3.7 and 3.8, and the latest tkinterweb version. Apologies if I am understanding any of these things incorrectly, I am still learning how to use these tools. Thank you!

Crashes

Hello!
sometimes my tk app crashes due a C assert failure. for example Assertion failed: (pItem->x.marker.flags), function HtmlDrawCleanup, file ../src/htmldraw.c, line 767..
Is it possible to handle asserts and call a function e.g. HtmlFrame.on_crash and destroy only frame (not all application) or to load a blank page?

Can't find package Tkhtml

Hi 'Andereoo',

I've been using tkinterweb (thanks!) in a Python 3 application on Windows and ran up against a problem in the compiled version of my app. Context is that I compiled my .py code to .pyd files using Cython, then used py2exe to generate an executable. My setup options are as follows:

setup(data_files=data_files,console=['picardy.py'], options={"py2exe" : {"includes" : ["inflect", "xml.dom", "xml.dom.minidom", "tkinter", "winsound"], 'packages': ['tkinterweb']}})

py2exe executes successfully but when I try to run the app I see:

Traceback (most recent call last):
  File "tkinterweb\bindings.pyc", line 82, in __init__
  File "tkinterweb\utilities.pyc", line 657, in load_tkhtml
_tkinter.TclError: can't find package Tkhtml

Do you have any idea what may be going on? I thought Tkhtml would be something I could install with pip but that doesn't seem to be the case.

Btw when I run from the Python interpreter there is no problem.

Thanks and best regards,
Rodney

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.