简体   繁体   English

投影到电视时调整图像大小我的python tkinter代码

[英]Resizing image when projecting into a TV my python tkinter code

I am trying to project my laptop screen into a 52" TV. I need the background image to fill the entire screen (independent of the size of the TV in which I am projecting). The window is able to resize when projecting, but the image does not. What I am missing ? 我正在尝试将笔记本电脑的屏幕投影到52英寸的电视中。我需要背景图片来填充整个屏幕(与投影电视的尺寸无关)。投影时窗口可以调整大小,但是图像没有,我想念什么?

I am using python and tkinter 我正在使用python和tkinter

from Tkinter import *

root = Tk()

photo = PhotoImage(file= r"a.gif")
w = Label(root, text="Hello, world!")
root.overrideredirect(True)
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
root.focus_set()  # <-- move focus to this widget
root.bind("<Escape>", lambda e: e.widget.quit())

canvas = Canvas(root) #, width=root.winfo_screenwidth(), height=root.winfo_screenheight())
canvas.pack(side='top', fill='both', expand='True') 
canvas.create_image(0, 0, image=photo, anchor='nw')

w.pack()

root.mainloop()

Images are a specific size. 图像是特定尺寸。 If you want the image to grow or shrink you'll have to manually adjust the image yourself when the window resizes. 如果您希望图像放大或缩小,则必须在调整窗口大小时自己手动调整图像。 Tkinter can only halve or double the size of an image. Tkinter只能将图像大小减半或加倍。 For anything fancier you'll need something like PIL or pillow. 对于任何发烧友,您都需要PIL或枕头之类的东西。

Since you know the maximum size is (I'm guessing) an HD display, you should probably start with an image that is 1920x1080 and then scale it down when you aren't projecting. 由于您知道最大尺寸是(我猜是)高清显示器,因此您可能应该以1920x1080的图像开始,然后在不投影时按比例缩小。

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

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