Python 如何在 Tkinter 中获取屏幕尺寸?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3949844/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 13:30:24 来源:igfitidea点击:
How to get the screen size in Tkinter?
提问by DonJuma
I would like to know if it is possible to calculate the screen size using tkinter.
我想知道是否可以使用 tkinter 计算屏幕尺寸。
I wanted this so that can make the program open up in the center of the screen...
我想要这个,这样可以让程序在屏幕中央打开......
采纳答案by mouad
import tkinter as tk
root = tk.Tk()
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
回答by Nandit Tiku
A possible solution
一个可能的解决方案
import os
os.system("xrandr | grep \* | cut -d' ' -f4")
My output:
我的输出:
1440x900
0

