我想知道是否可以使用Tkinter计算屏幕大小。
我想让程序在屏幕中央打开……
发布于 2010-10-17 01:33:27
import tkinter as tk
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
发布于 2010-10-17 02:22:36
一种可能的解决方案
import os
os.system("xrandr | grep \* | cut -d' ' -f4")
我的输出:
1440x900
0
发布于 2021-02-18 03:19:04
对于Windows:
您可以让进程意识到DPI,以处理缩放显示。
import ctypes
try: # Windows 8.1 and later
ctypes.windll.shcore.SetProcessDpiAwareness(2)
except Exception as e:
pass
try: # Before Windows 8.1
ctypes.windll.user32.SetProcessDPIAware()
except: # Windows 8 or before
pass
在mouad's answer上扩展,此函数能够处理多显示器,并返回当前屏幕的分辨率:
import tkinter
def get_display_size():
root = tkinter.Tk()
root.update_idletasks()
root.attributes('-fullscreen', True)
root.state('iconic')
height = root.winfo_screenheight()
width = root.winfo_screenwidth()
root.destroy()
return height, width
https://stackoverflow.com/questions/3949844
复制相似问题