如何在不输入屏幕分辨率的情况下创建屏幕大小的窗口(通过 Tkinter)?

问题描述 投票:0回答:1

我是 Python 的新手,但我经常使用 Ren'Py。现在我正在尝试制作一个带有图像(最好是动画)的透明窗口,该图像将出现在 Ren'Py 窗口之外的玩家桌面上,但我有一个问题:如果我不写,该窗口就不会出现它的分辨率仅包含数字,但我需要它是播放器屏幕的分辨率(变量)

这是我的代码和注释:

import tkinter as tk
from tkinter import *
    
window = tk.Tk()
scr_width = window.winfo_width()
scr_height = window.winfo_height()
screen_resolution = str(scr_width)+"x"+str(scr_height)
    
    
window.overrideredirect(True) # hides the taskbar
    
window.geometry("1536x864") # only this works, but I need it to use the player's screen resolution
# window.geometry(screen_resolution) # window just doesn't appear!
# window.geometry("{}x{}".format(scr_width, scr_height)) # window doesn't appear as well

window.overrideredirect(True) # hides the taskbar
window.after(5000, lambda: window.destroy()) # closes the window after 10 seconds


transparent_color = '#abcdef'
window.wm_attributes('-transparentcolor', transparent_color)

img = PhotoImage(file="my_path/my_img.png")
canvas = Label(window, image=img, relief="solid", width= 20, height= 8, anchor= CENTER, bg=transparent_color)
canvas.pack(fill=BOTH, expand=1)

window.mainloop()
python
1个回答
0
投票

你当然可以将

screen_resolution
设置为变量
使用
#screen_resolution = "1536x864"
会起作用

但是您检查过变量返回的内容吗?

scr_width = window.winfo_width()
scr_height = window.winfo_height()

我怀疑

screen_resolution = str(scr_width) + "x" + str(scr_height)
是“1 x 1”,这就是为什么你看不到任何东西

以下可能会给你更好的结果

scr_width = window.winfo_screenwidth()
scr_height = window.winfo_screenheight()
© www.soinside.com 2019 - 2024. All rights reserved.