Skip to content

Commit ae9bbba

Browse files
tkfstevengj
authored andcommitted
Support closing the first (root) window in Tk (#591)
* Support closing the first (root) window in Tk * Simplify Tk_eventloop Note: _tkinter is available both in Python 3 and 2. * https://docs.python.org/3/library/tkinter.html#tkinter-modules * https://docs.python.org/2/library/tkinter.html#tkinter-modules * https://github.com/ipython/ipython/blob/5.8.0/IPython/terminal/pt_inputhooks/tk.py#L45
1 parent 8c43f1b commit ae9bbba

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/gui.jl

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,20 @@ function wx_eventloop(sec::Real=50e-3)
192192
end
193193

194194
# Tk: (Tkinter/tkinter module)
195+
# based on https://github.com/ipython/ipython/blob/7.0.1/IPython/terminal/pt_inputhooks/tk.py
195196
function Tk_eventloop(sec::Real=50e-3)
196197
Tk = pyimport(tkinter_name())
198+
_tkinter = pyimport("_tkinter")
199+
flag = _tkinter[:ALL_EVENTS] | _tkinter[:DONT_WAIT]
200+
root = PyObject(nothing)
197201
install_doevent(sec) do async
198-
root = Tk["_default_root"]
202+
new_root = Tk["_default_root"]
203+
if new_root.o != pynothing[]
204+
root = new_root
205+
end
199206
if root.o != pynothing[]
200-
pycall(root["update"], PyObject)
207+
while pycall(root["dooneevent"], Bool, flag)
208+
end
201209
end
202210
end
203211
end

0 commit comments

Comments
 (0)