Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 将tkinter窗口内容转换为图像_Python 3.x_Tkinter - Fatal编程技术网

Python 3.x 将tkinter窗口内容转换为图像

Python 3.x 将tkinter窗口内容转换为图像,python-3.x,tkinter,Python 3.x,Tkinter,我想将tkinter窗口内容转换为.bmp图像(或其他类型的图像文件),并将结果保存在用户选择的目录中。如何进行转换 保存代码如下: import os import tkinter as tk from tkinter import filedialog root=tk.Tk() tk.Label(root, text="Hello").grid(row=1, sticky='w') dir_path=filedialog.askdirectory(parent=root, initial

我想将tkinter窗口内容转换为.bmp图像(或其他类型的图像文件),并将结果保存在用户选择的目录中。如何进行转换

保存代码如下:

import os
import tkinter as tk
from tkinter import filedialog

root=tk.Tk()
tk.Label(root, text="Hello").grid(row=1, sticky='w')

dir_path=filedialog.askdirectory(parent=root, initialdir="/", title="Choose a folder")
if len(dir_path)>0:
    Element= ...# Here I want to put the .bmp image resulting in the conversion of the created tkinter window 
    Element_name="image_1.bmp"
    file_path=os.path.join(dir_path, Element_name)
    Element.save(file_path, "BMP")

请,有人能帮我吗?你可以用.ps导出画布的内容,但是如果你想要完整的窗口,你需要截图,例如,@j_4321在完整的代码中,我有一个Excel文件,并且必须为此文件的每一页创建一个画布(即在完整的代码中,发布的代码的一部分在循环中)。因此,对于每个已创建的画布,我无法打开图像(尚未创建图像(因为我只有.ps文件)并拍摄屏幕截图)。我不明白您想做什么。您正在谈论打开图像,而我认为您希望将窗口另存为图像。如果你编辑你的问题以更清楚地说出你想做什么,可能会有人回答。请,有人能帮我吗?你可以用.ps导出画布的内容,但是如果你想要完整的窗口,你需要截图,例如,在完整的代码中使用@j_4321,我有一个Excel文件,必须为此文件的每一页创建一个画布(即在完整的代码中,发布的代码的一部分在循环中)。因此,对于每个已创建的画布,我无法打开图像(尚未创建图像(因为我只有.ps文件)并拍摄屏幕截图)。我不明白您想做什么。您正在谈论打开图像,而我认为您希望将窗口另存为图像。也许如果你编辑你的问题,更清楚地说出你想做什么,有人可能会回答。