【问题标题】:In jupyter notebook how to bring tkinter.filedialog window to the top of all windows?在 jupyter notebook 中,如何将 tkinter.filedialog 窗口置于所有窗口的顶部?
【发布时间】:2017-02-17 21:10:50
【问题描述】:

我正在使用 python 3 在 jupyter notebook 中运行以下内容:

import tkinter
import tkinter.filedialog
%gui tk
my_file = tkinter.filedialog.askopenfilename()

当我运行它时,tkinter 窗口会在浏览器后面的某个地方启动。我怎样才能把它提升到顶部?

【问题讨论】:

    标签: python-3.x user-interface tkinter jupyter-notebook jupyter


    【解决方案1】:

    我已经在几个 jupyter 笔记本中测试了以下代码 sn-p,它似乎可以工作:

    from tkinter import*
    # Create Tk root
    root = Tk()
    # Hide the main window
    root.withdraw()
    root.call('wm', 'attributes', '.', '-topmost', True)
    
    from tkinter import filedialog
    infiles = filedialog.askopenfilename(multiple=True)
    
    %gui tk
    

    这就是我目前所拥有的,但我会继续努力。我认为可能有一些 JavaScript 解决方案。

    【讨论】:

    • 当我在 JupyterLab(v3.1.14 服务器与 Jupyter_client v6.1.1.12)中运行此代码时收到运行时警告 C:\ProgramData\Anaconda3\envs\PyQt5Options\lib\site-packages\ ipykernel\eventloops.py:256: RuntimeWarning: coroutine 'Kernel.do_one_iteration' is never awaited self.func() RuntimeWarning: E​​nable tracemalloc to get the object allocation traceback
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-29
    • 2023-03-29
    • 2010-11-06
    • 2013-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多