【问题标题】:I want to open a Text file in Gedit, using python tkinter我想在 Gedit 中打开一个文本文件,使用 python tkinter
【发布时间】:2021-02-03 23:54:14
【问题描述】:

我只是在 linux 上工作并使用 python tkinter,并且想在 gedit 中打开一个文本文件,而不是在 cli 中打开它。

【问题讨论】:

  • 那么问题是什么?
  • 你可以使用subprocess.Popen():subprocess.Popen(['gedit', '/path/to/the/text/file'])

标签: python python-3.x python-2.7 tkinter


【解决方案1】:

你可以试试webbrowser:

import webbrowser

def open_file(file_name):
    webbrowser.open(file_name)

这应该在您的默认文本编辑器中打开所述文件(如 Windows 中的记事本或 linux 中的 gedit)。您可以在 GUI 中添加一个按钮并调用运行上述代码的函数。

【讨论】:

    猜你喜欢
    • 2011-12-20
    • 1970-01-01
    • 2018-02-26
    • 1970-01-01
    • 1970-01-01
    • 2015-05-06
    • 2021-08-08
    • 1970-01-01
    • 2021-03-22
    相关资源
    最近更新 更多