【发布时间】: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