[英]How to set the root window size to half of the screen width and height Python Tkinter
I am trying to get the width and height of the users monitor size. 我试图获取用户监视器大小的宽度和高度。 Which I can get that but now my main problem is how to set the root window to half the width ad height but I have run into a wall and I can not find anything online that can help em what am I doing wrong here?
我可以得到这个,但现在我的主要问题是如何将根窗口设置为宽度广告高度的一半,但我遇到了一堵墙,我在网上找不到任何可以帮助我的东西,我在这里做错了什么?
Here is the code: 这是代码:
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry("widthxheight")
I am aware that it is set to go to the full screen size. 我知道它设置为全屏尺寸。 Which is what I want to do first.
这是我想先做的。
To make the window full screen size, use this: 要使窗口全屏大小,请使用:
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry(f'{width}x{height}')
To make it half the screen size, just put /2
after width
and height
, like this: 要使它成为屏幕尺寸的一半,只需在
width
和height
之后放置/2
,如下所示:
root.geometry(f'{width/2}x{height/2}')
For python 3.5 and lower, use one of the following string formatting syntaxes : 对于python 3.5及更低版本,请使用以下字符串格式化语法之一 :
root.geometry('%sx%s' % (width/2, height/2))
# OR
root.geometry("{}x{}".format(width, height))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.