繁体   English   中英

如何在 tkinter 中以 pdf 格式保存画布?

[英]How to save the canvas in tkinter in pdf format?

我想保存整个画布(在 tkinter 中创建),包括高质量的可滚动区域并转换为 pdf/HD 图像。 你能帮我解决这个问题吗?

我尝试使用 postscript,但它不包括可滚动区域,而且质量很低。

你可以使用 PIL 库来截图,我把一些代码放在一起,它并不完美只是一个例子。

我会改进的事情,首先加载表单并在框架加载后在另一个线程中截取屏幕截图。 获取帧的位置并将其传递给 take_screenshot()。

import tkinter as tk
from PIL import ImageGrab

def take_screenshot():
    # Take a screenshot of the Tkinter window
    image = ImageGrab.grab(bbox=(50, 50, 600, 500))
    image.save("screenshot.png")

# Create a new Tkinter window
window = tk.Tk()
window.geometry('600x400+50+50')

# Add a label to the winow
label = tk.Label(window, text="Enter your name:")
label.pack()

# Add a text field to the window
text_field = tk.Entry(window)
text_field.pack()

# Add a submit button to the window
submit_button = tk.Button(window, text="Submit")
submit_button.pack()

# Take a screenshot of the Tkinter window
take_screenshot()

# Start the Tkinter event loop
window.mainloop()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM