简体   繁体   English

我想在我的tkinter窗口中嵌入python控制台..我怎么能这样做?

[英]I want to embed python console in my tkinter window.. How can i do it?

I am making a text editor and want to add a feature of IDLE in my app. 我正在制作文本编辑器,并希望在我的应用程序中添加IDLE功能。 So i want an frame with python IDLE embedded in it with all menus and features which original python IDLE gives. 所以我想要一个嵌入了python IDLE的框架,其中包含原始python IDLE提供的所有菜单和功能。

I looked in source of idle lib but cannot find a solution. 我查看了空闲lib的源代码,但无法找到解决方案。

    try:
    import idlelib.pyshell
except ImportError:
    # IDLE is not installed, but maybe pyshell is on sys.path:
    from . import pyshell
    import os
    idledir = os.path.dirname(os.path.abspath(pyshell.__file__))
    if idledir != os.getcwd():
        # We're not in the IDLE directory, help the subprocess find run.py
        pypath = os.environ.get('PYTHONPATH', '')
        if pypath:
            os.environ['PYTHONPATH'] = pypath + ':' + idledir
        else:
            os.environ['PYTHONPATH'] = idledir
    pyshell.main()
else:
    idlelib.pyshell.main()

This code is of pyshell.pyw found under idlelib folder in all python install 这段代码是在所有python安装的idlelib文件夹下找到的pyshell.pyw

I searched the idle.pyw and found that it uses a program pyshell which is real shell. 我搜索了idle.pyw,发现它使用了一个真正的shell程序pyshell。 So how can i embed it. 那么我怎么能嵌入它。

I want a Tkinter frame with python IDLE shell embedded in it.Please give the code. 我想要一个嵌入了python IDLE shell的Tkinter框架。请给出代码。 Thanks in advance. 提前致谢。

Stackoverflow is not a code writing service. Stackoverflow不是代码编写服务。 Rather, the aim is to help you write code. 相反,目的是帮助编写代码。 It is usually best if one writes some code before asking a question, but in this case, you got stuck before coding. 通常最好是在问一个问题之前写一些代码,但在这种情况下,你在编码之前就被卡住了。

idlelib implements IDLE. idlelib实现了IDLE。 While you are free to use it otherwise, it is private in the sense that code and interfaces can change in any release without the usual back-compatibility constraints. 虽然您可以自由地使用它,但它是私有的,因为代码和接口可以在任何版本中更改,而不会出现通常的反向兼容性约束。 Import and use idlelib modules at your own rish. 您自己导入并使用idlelib模块。

Currently, a Shell window is a Toplevel with a Menu and a Frame. 目前,Shell窗口是具有菜单和框架的Toplevel。 The latter has a Text and vertical Scrollbar. 后者有一个文本和垂直滚动条。 It is not possible to visually embed a Toplevel within a frame (or within another Toplevel or root = Tk()). 无法在框架内(或在另一个Toplevel或root = Tk()内)可视地嵌入Toplevel。 top = Toplevel(myframe) works, but top cannot be place d, pack ed, or grid ded within myframe . top = Toplevel(myframe)可以工作,但top不能在myframe place d, pack ed或grid ded。

I hope in the future to refactor editor.py and pyshell.py so as to separate the window with menu from the frame with scrollable text. 我希望将来能够重构editor.py和pyshell.py,以便将带有菜单的窗口与具有可滚动文本的框架分开。 The result should include embeddable EditorFrame and ShellFrame classes that have parent as an arguments. 结果应包括具有parent作为参数的可嵌入EditorFrame和ShellFrame类。 But that is in the future. 但那是在未来。

Currently, one can run IDLE from within python with import idlelib.idle . 目前,可以使用import idlelib.idle从python中运行IDLE。 However, because this runs mainloop() (on its own root), it blocks and does not finish until all IDLE windows are closed. 但是,因为它运行mainloop()(在它自己的根目录下),所以它会阻塞并且在所有IDLE窗口关闭之前不会完成。 This may not be what one wants. 这可能不是人们想要的。

If having Shell run in a separate window is acceptable, one could extract from python.main the 10-20 lines needed to just run Shell. 如果在单独的窗口中运行Shell是可以接受的,可以从python.main中提取运行Shell所需的10-20行。 Some experimentation would be needed. 需要进行一些实验。 If the main app uses tkinter, this function should take the app's root as an argument and not call mainloop(). 如果主应用程序使用tkinter,则此函数应将应用程序的root作为参数,而不是调用mainloop()。

Tcl having Tkcon.tcl . Tcl有Tkcon.tcl。 when each thread source (means run/exec) the Tkcon.tcl each thread will pop up a Tk shell/Tk console/tkcon.tcl very good idea for debug. 当每个线程源(意味着运行/执行)Tkcon.tcl时,每个线程都会弹出一个Tk shell / Tk console / tkcon.tcl非常好的调试思路。 and print message individually by thread. 并通过线程单独打印消息。 Python having idle.py ... and how to use it ? Python有idle.py ...以及如何使用它? still finding out the example . 仍然找到了这个例子。 The are same Tk base . 是相同的Tk基地。 why can't find an suitable example? 为什么找不到合适的例子? so far ... keep finding... 到目前为止......继续寻找......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我想使用 python 在新的 tkinter 窗口中打印我的所有 excel 数据 - I want to print my all excel data in new tkinter window using python 如何让我的透明窗口接受鼠标事件? - Python/Tkinter - How do I get my transparent window to accept mouse events? - Python/Tkinter 如何在使用Tkinter时删除Python Shell窗口? - How can I remove the Python Shell window while using Tkinter? python程序终止后,如何保持控制台窗口打开以查看产生的任何错误? - How do I keep a console window open after my python program terminates to see any errors produced? 我想要一个按钮来执行双重命令一个命令将终止我当前的 window 另一个命令将在 tkinter 中打开一个新的 window - I want a single button to do double command one command will terminate my present window and another command will open a new window in tkinter 如何使用Python控制台执行网站上方的窗口? - How do I execute a window above a website, with a Python console? 我想用“%”号显示我的EXCEL数据。 我如何使用python做到这一点 - I want to display my EXCEL data with “%” sign. How can i do so by using python 如何将 Opencv 集成到 Tkinter 窗口中 - How can I integrate Opencv into a Tkinter window 如何在 tkinter 中创建弹出窗口? - How do I create a popup window in tkinter? Tkinter:如何清除窗口? - Tkinter: How do I clear the window?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM