python - 为什么我的 winfo_screenwidth() 和 winfo_screenwidth() 得到一些奇怪的数字? Tkinter

标签 python tkinter screen-resolution

为什么 ramy winfo_screenmmwidth() 和 winfo_screenmmheight() 会得到一些奇怪的数字?

我必须将宽度乘以 3.78,将高度乘以 3.779 这是我的代码:

from tkinter import *
from PIL import ImageTk,Image


root = Tk()
root.title("My Program")

# Designate the height and width of our app
app_width = 500
app_height = 500

screen_width = root.winfo_screenmmwidth()
screen_height = root.winfo_screenmmheight()


dpi = root.winfo_fpixels('1i')

real_width = int(screen_width * 3.78)
real_height = int(screen_height * 3.779)

root.geometry(f"{app_width}x{app_height}+{1000}+{200}")

mylbl = Label(root,text=f"{real_width}x{real_height}")
mylbl.pack()





root.mainloop()

当我不做奇怪的乘法时,我得到 508x286 而不是 1920x1080

是什么原因造成的?

最佳答案

为了让它发挥作用,你必须改变

winfo_screenmmwidth()

进入:

winfo_screenwidth()

高度也一样。否则,它以毫米为单位进行测量。

P.S.:对评论中的人负责

关于python - 为什么我的 winfo_screenwidth() 和 winfo_screenwidth() 得到一些奇怪的数字? Tkinter ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73055247/

相关文章:

python - 如何获取 javascript 存储的 cookie?

python - 将非标准pdf拟合到matplotlib中的直方图

winforms - VS2010表单大小和屏幕分辨率问题

Python脚本没有选择在excel宏中选择的正确日期

python - scikit-learn, linearsvc - 如何从经过训练的 SVM 中获取支持向量?

python - 使用 Tkinter 在闪烁的光标下方打开一个新窗口

python - Pandastable 表无法使用向下键自动向下滚动

python - 使用 tkinter 输入一个变量,被调用

html - 如何使 css 动画仅在某些屏幕分辨率下有效?

java - Android 布局文件夹