You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looks like there is no way to get window id (NSView pointer) in tkinter on Mac, so that browser can be embedded in that window. From tk manual:
winfo id window
Returns a hexadecimal string giving a low-level platform-specific identifier for window. On Unix platforms, this is the X window identifier. Under Windows, this is the Windows HWND. On the Macintosh the value has no meaning outside Tk.
Below is the error when trying to embed CEF browser using that negative window identifier:
[tkinter_.py] winfo_id()=-1683723760
Exception in Tkinter callback
Traceback (most recent call last):
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 1470, in __call__
return self.func(*args)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk/Tkinter.py", line 531, in callit
func(*args)
File "../examples/tkinter_.py", line 276, in embed_browser
window_info.SetAsChild(self.winfo_id())
File "thon/window_info.pyx", line 82, in cefpython_py27.WindowInfo.SetAsChild (cefpython.cpp:39561)
OverflowError: can't convert negative value to size_t
The text was updated successfully, but these errors were encountered:
cztomczak
changed the title
Mac: tkinter example error because winfo_id() returns a negative value
Mac: tkinter_.py example: error with winfo_id() returning a negative value
Mar 1, 2017
Fix tkinter error on Mac "unrecognized selector sent to instance"
(Issue #306"). CEF must be initialized after Tk.
Fix error with winfo_id() returning a negative value (Issue #308).
This was resolved by obtaining NSView pointer using PyObjC
package.
There is yet another error "Segmentation fault: 11" which
crashes app often, however it's hard to debug it (Issue #309).
Fixed it by using PyObjC package to obtain NSView pointer:
def get_window_handle(self):
if self.winfo_id() > 0:
return self.winfo_id()
elif MAC:
# On Mac window id is an invalid negative value (Issue #308).
# This is kind of a dirty hack to get window handle using
# PyObjC package. If you change structure of windows then you
# need to do modifications here as well.
# noinspection PyUnresolvedReferences
from AppKit import NSApp
# noinspection PyUnresolvedReferences
import objc
# Sometimes there is more than one window, when application
# didn't close cleanly last time Python displays an NSAlert
# window asking whether to Reopen that window.
# noinspection PyUnresolvedReferences
return objc.pyobjc_id(NSApp.windows()[-1].contentView())
else:
raise Exception("Couldn't obtain window handle")
Looks like there is no way to get window id (NSView pointer) in tkinter on Mac, so that browser can be embedded in that window. From tk manual:
Reference: https://www.tcl.tk/man/tcl8.4/TkCmd/winfo.htm#M17
Below is the error when trying to embed CEF browser using that negative window identifier:
The text was updated successfully, but these errors were encountered: