Skip to content

Conversation

@tkf
Copy link
Member

@tkf tkf commented Oct 13, 2018

src/gui.jl Outdated
_tkinter = pyimport("_tkinter")
end
flag = _tkinter[:ALL_EVENTS] | _tkinter[:DONT_WAIT]
root = Tk["_default_root"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just root = PyObject(nothing) since it will get updated in the event loop anyway.

end
if root.o != pynothing[]
pycall(root["update"], PyObject)
while pycall(root["dooneevent"], Bool, flag)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is that the correct spelling?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see, it's "do one event"

@tkf
Copy link
Member Author

tkf commented Oct 13, 2018

OK. Applied the fix.

@stevengj
Copy link
Member

Why the change from root.update to dooneevent?

@tkf
Copy link
Member Author

tkf commented Oct 14, 2018

Right, I should have left comments. Calling update after closing the first window throws. You can see it by

julia> using PyCall, PyPlot

julia> figure(1)
       plot([1,2,3])
       figure(2)
       plot([1,2,3])
       root = pyimport("tkinter")["_default_root"]
       close(1)

julia> pycall(root["update"], PyObject)
ERROR: PyError ($(Expr(:escape, :(ccall(#= /home/takafumi/.julia/dev/PyCall/src/pyfncall.jl:44 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class '_tkinter.TclError'>
TclError('can\'t invoke "update" command: application has been destroyed')
  File "/usr/lib64/python3.7/tkinter/__init__.py", line 1174, in update
    self.tk.call('update')

I used dooneevent simply because IPython uses it: https://github.com/ipython/ipython/blob/7.0.1/IPython/terminal/pt_inputhooks/tk.py

It seems that dooneevent (which presumably wraps Tcl_DoOneEvent) acts on the whole eventloop: https://www.tcl.tk/man/tcl8.0/TclLib/DoOneEvent.htm

So I guess that's why it works even after the root window is closed.

@stevengj stevengj merged commit ae9bbba into JuliaPy:master Oct 14, 2018
@tkf tkf deleted the multi-tk branch November 4, 2018 13:39
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

Successfully merging this pull request may close these issues.

Cannot open multiple figures

2 participants