2 回答

TA貢獻1909條經(jīng)驗 獲得超7個贊
您可以在不使用小部件的情況下?lián)碛斜尘皥D像Canvas,這樣做將允許您使用 tkinter 的幾何管理器來放置小部件。我不太明白Raspberry Pi 的320x240 屏幕和1280x480 HDMI 之間的關系。
下面的代碼說明了如何顯示背景圖像和它上面的一些小部件。還有一個Button可以在您想要的兩個之間切換窗口的大小。
from PIL import Image, ImageTk
try:
import Tkinter as tk
except:
import tkinter as tk
path_to_bkgr_img = "redpoly2.jpg"
WIN_SIZES = (320, 240), (1280, 480)
# Translates an rgb tuple of int to a tkinter friendly color code.
def _from_rgb(rgb):
return "#%02x%02x%02x" % rgb
def change_size():
""" Sets/changes window size to next one available in WIN_SIZES. """
global cur_size
cur_size = (cur_size + 1) % len(WIN_SIZES)
config_window()
def config_window():
""" Sets root window's title, size, and background image. """
global background_label
geometry = '{}x{}'.format(*WIN_SIZES[cur_size])
root.geometry(geometry)
root.title(geometry)
# Resize background to fit window size.
btn_img = background_image.resize(WIN_SIZES[cur_size], resample=Image.BICUBIC)
btn_img = ImageTk.PhotoImage(btn_img) # Make tkinter compatible.
if not background_label: # Create Label if necessary.
background_label = tk.Label(root)
background_label.config(image=btn_img)
background_label.image = btn_img # Keep reference.
background_label.place(x=0, y=0, relwidth=1, relheight=1)
root = tk.Tk()
background_image = Image.open(path_to_bkgr_img)
background_label = None
cur_size = 0
config_window()
titleLabel = tk.Label(root, fg="white", text="TEXT", borderwidth=2, relief="solid",
bg=_from_rgb((239, 36, 37)), font=("Courier", 44))
titleLabel.pack(padx=5, pady=5, expand=1)
logButton = tk.Button(root, fg="white", text="Change Size", command=change_size,
borderwidth=2, relief="raised", bg=_from_rgb((239, 36, 37)),
font=("Courier", 22))
logButton.pack(padx=5, pady=5, expand=1)
root.bind_all('<KeyPress-Escape>', lambda *event: quit()) # Press Esc key to quit app.
root.mainloop()
以下是顯示每種尺寸所顯示內(nèi)容的屏幕截圖:

TA貢獻1875條經(jīng)驗 獲得超3個贊
RPi 的輸出可以在config.txt
/boot 分區(qū)上的文件中配置。通過參考config.txt 視頻頁面,您可以將 HDMI 的輸出設置為特定模式。在您的情況下,這可能需要在 raspberry pi 論壇中描述的自定義設置。
config.txt
您使用以下配置字符串指定新模式:
hdmi_cvt=<width> <height> <framerate> <aspect> <margins> <interlace> <rb>
在哪里:
Value Default Description
width (required) width in pixels
height (required) height in pixels
framerate (required) framerate in Hz
aspect 3 aspect ratio 1=4:3, 2=14:9, 3=16:9, 4=5:4, 5=16:10, 6=15:9
margins 0 0=margins disabled, 1=margins enabled
interlace 0 0=progressive, 1=interlaced
rb 0 0=normal, 1=reduced blanking
添加回答
舉報