【问题标题】:tkinter not responding when a text file is opened打开文本文件时 tkinter 没有响应
【发布时间】:2018-09-12 13:50:49
【问题描述】:

我有一个带有按钮的 tkinter 程序。该按钮的作用是使用记事本在我的桌面上打开一个文本文件。代码如下:

import tkinter as tk
import os


def open_file():
    file = os.path.expanduser('~/Desktop/a.txt')
    os.system("notepad.exe " + file)


root = tk.Tk()

button = tk.Button(root, text='open', command=open_file)
button.grid()

root.mainloop()

代码运行并且程序正在运行,但问题是当我单击按钮时,文本文件打开但 tkinter 窗口在我关闭文本文件之前不会响应。我正在使用 Python 3 和 Windows 10。

任何帮助将不胜感激。 谢谢。

【问题讨论】:

  • 使用os.system("start notepad.exe ...") - 一旦启动指定的程序,'start' 命令就会返回。
  • 谢谢。成功了!

标签: python python-3.x tkinter


【解决方案1】:

只需使用:os.system("start notepad.exe")

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 2013-05-02
    • 2019-12-24
    • 1970-01-01
    • 2014-03-20
    相关资源
    最近更新 更多