我在python2x中玩tkinter,每当我使用filename = tkFileDialog.askopenfilename()
时,我可以轻松地打开一个文件供使用,然后对话框窗口自动关闭。在
不知何故,这在python3x中不起作用
import tkinter
from tkinter import filedialog
def character_mentions():
filename = filedialog.askopenfilename()
with open(filename, 'r') as infile:
reader = csv.reader(infile)
dict_of_mentions = {rows[1]:rows[2] for rows in reader}
print(dict_of_mentions)
这给了我想要的输出,但是空的根窗口保持打开,空白。当我按下X按钮时,它会冻结并迫使我用任务管理器关闭它。在
有什么办法吗?提前谢谢!在
您需要创建一个tkinter实例,然后隐藏主窗口。在
在函数中,一旦函数完成,您可以简单地
destroy()
tkinter实例。在相关问题 更多 >
编程相关推荐