Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
irutel opened this issue Jul 15, 2021 · 18 comments

Comments

@irutel
Copy link

irutel commented Jul 15, 2021

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?

@Andereoo
Copy link
Owner

Hello,

Thank you for letting me know about this. Perhaps try running your code from Python (and not PyCharm), or running the Tkinterweb Demo (ie. import tkinterweb; tkinterweb.Demo()). Let me know what happens. If you can send me a simplified version of your code that has the issue so that I can try to identify the cause, that would be really helpful. Thanks!

@irutel
Copy link
Author

irutel commented Jul 16, 2021 via email

@Andereoo
Copy link
Owner

Hi!

I can't seem to find the files, maybe something went wrong when you sent them?

@irutel
Copy link
Author

irutel commented Jul 18, 2021 via email

@Andereoo
Copy link
Owner

Hello,

It looks like email reply to Github is stripping attachments. If you go to #19 you should be able to drag and drop your zip file. This should upload it.

@irutel
Copy link
Author

irutel commented Jul 19, 2021

Here are the files.
test.zip

@Andereoo
Copy link
Owner

Hi,

This seems to be a Tkhtml bug. For some reason when used with a tk.Text widget in a ttk.Notebook, selecting the tab with Tkhtml causes the app to crash. Try this code if you're curious:

import tkinter as tk
from tkinter import ttk
import os

class TkhtmlWidget(tk.Widget):
    def __init__(self, master):
        master.tk.call("load", "C://path/to/tkinterweb/Windows/64-bit/Tkhtml30.dll")
        tk.Widget.__init__(self, master, "html")

root = tk.Tk()

tabframe = ttk.Notebook(root)
tabframe.pack(fill="both", expand=True)

textframe = tk.Text(root)
tabframe.add(textframe, text="TEXT")

htmlframe = TkhtmlWidget(root)
tabframe.add(htmlframe, text="HTML")

root.mainloop()

Selecting the 'HTML' tab will crash the app. This issue only seems to be present in 64-bit Windows. I'll keep looking for a fix, or at least a workaround.

@irutel
Copy link
Author

irutel commented Aug 10, 2021

Thanks for the verification and tracking down the specific issue (even though it is not in your project). I anxiously await a work-around or resolution/update to Tkhtml, either of which might allow a table formatted html file loaded into the tab. I can always open a new window, but that would be clunky for my app. Thanks for the help, I will await a fix! Thanks!

@Andereoo
Copy link
Owner

Unfortunately, I haven't been able to find any fixes yet. There are two things that you could do at this point. Firstly, it seems that you are using both tkinterweb.HtmlFrame and tk_html_widgets.HTMLScrolledText in your ttk.Notebook. Since HTMLScrolledText is derived from tk.Text, you are encountering issues. You could consider using only HtmlFrame to display HTML in the Notebook. This should avoid any tk.Text+Tkhtml+ttk.Notebook bugs. Alternatively, you could make your own Notebook widget. Simply create one button per page and put a Frame under the buttons. Make each page a child of the frame. Then, make a callback that runs when a button is clicked, which would call pack_forget on the currently displayed page, and pack on the new page. It's not ideal, but it should work. If I were you, I'd use the first workaround, but if that is not practical for you, the second workaround shouldn't take too long to make. I can provide some code if needed.

@irutel
Copy link
Author

irutel commented Aug 10, 2021

I think I attempted to run it all with HtmlFrame before and had a similar problem. The HTMLScrolledText provided stable function for the other tabs . . . In any case, I updated the code to ONLY use calls to HtmlFrame and it crashes again.

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: 0xf08 Faulting application start time: 0x01d78e17b6eefb63 Faulting application path: C:\Users\irutel\AppData\Local\Programs\Python\Python38\python.exe Faulting module path: C:\Users\irutel\AppData\Local\Programs\Python\Python38\DLLs\tcl86t.dll Report Id: 1a9998f5-025c-45f6-8009-45ce29b27432 Faulting package full name: Faulting package-relative application ID:

I will see about a test file with the same setup to determine if I have the crash in a simplified script.

The Python output after the error is:
Process finished with exit code -1073741819 (0xC0000005)

@irutel
Copy link
Author

irutel commented Aug 10, 2021

Here is the updated code with only the tkinterweb functions (HtmlFrame) and the files to test. It still crashes, even in the simplified format.
test2.zip

@mmarquet
Copy link

mmarquet commented Aug 11, 2021

Just chiming in to say I have the exact same issue than irutel and I'm heavily interested in a fix. I'm loading an html content read from a local file that I want to display in a tab and I'm experiencing the same symptoms. Thanks for bringing this up irutel!

@Andereoo
Copy link
Owner

Andereoo commented Sep 3, 2021

Hi @irutel @mmarquet,

Sorry for the late response. I still haven't been able to find a fix for this Tkhtml bug. That being said, I've made a wrapper for ttk.Notebook that works with TkinterWeb.

It displays and manages pages on it's own but allows ttk.Notebook to still display tabs. This means that is compatible with TkinterWeb but looks and behaves just like ttk.Notebook. Themes should work as well. I've tried to make it a drop-in replacement for ttk.Notebook, so you shouldn't have any trouble using it. Here is the source code. Simply copy the Notebook class into your script or paste the ModifiedNotebook.py file into the same folder as your code and put from ModifiedNotebook import Notebook at the top of your script. Then, instead of using tabControl1 = ttk.Notebook(...), use tabControl1 = Notebook(...). Let me know if it works as expected. If it works well on your end I will include it in the next update. Otherwise, let me know and I'll keep working on it!

@mmarquet
Copy link

mmarquet commented Sep 3, 2021

Hey @Andereoo, thanks for the not so late response :) I'm out of the office until monday but I'll definitely give this a try then. Thanks for your work, I will keep you posted! 👍

@irutel
Copy link
Author

irutel commented Sep 3, 2021

@Andereoo,
(and @mmarquet)
I have implemented the file/import method and changed the reference to your Notebook. I am happy to report I have stability AND I have some nicely formatted (html5 table calls) which are now displayed, without the windows error (and python crash). I am very thankful for your time and updated code for Notebook. I also appreciate the mods, advice and the updated code to implement. I will let you know if I experience any other odd behaviors, but at the moment, I think you have answered all my questions. The wait was not too long and definitely worth it! Thanks again!

@mmarquet
Copy link

mmarquet commented Sep 3, 2021

I'm excited to read that, can't wait to implement it too!

@mmarquet
Copy link

mmarquet commented Sep 6, 2021

I can confirm it works on my end too, I also used the file importing method. Thanks for the fix!

@Andereoo
Copy link
Owner

Andereoo commented Sep 7, 2021

@mmarquet @irutel Thanks for confirming that the code works on your end. I have updated TkinterWeb today. The new Notebook widget is included. You can now use from tkinterweb import Notebook to use the modified Notebook widget. As always, let me know if you encounter any other issues!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants