简体   繁体   English

如何将根窗口大小设置为屏幕宽度和高度的一半Python Tkinter

[英]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: 要使它成为屏幕尺寸的一半,只需在widthheight之后放置/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.

相关问题 如何在 tkinter 中创建具有全屏宽度/高度的 window? - How to create window with full screen width/height in tkinter? 当我使用网格时,我使用了一半的屏幕宽度和屏幕高度,但出现了这些错误 tkinter python - When I am using the grid I used half the screen width and screen height but I got these errors tkinter python 如何在 Python Tkinter 中将画布的宽度设置为屏幕的宽度? - How can I set the width of a canvas to the width of the screen in Python Tkinter? 如何设置 Python Pygame window 屏幕的最小和最大宽度和高度? - How to I set minimum and maximum width and height of the screen of my Python Pygame window? Python tkinter屏幕宽度和高度辅助显示 - Python tkinter screen width and height secondary display python Tkinter:如何不允许窗口大于屏幕大小 - python Tkinter: how to disallow a window growing bigger than screen size 如何为 tkinter 中的小部件设置固定宽度和高度? - How to set fixed width and height to widgets in tkinter? 使用Python在Linux中将活动窗口的大小调整为屏幕大小的一半吗? - Use Python to resize the active window to half the screen size in Linux? 如何在Python Tkinter中编辑根窗口 - How to edit the root window in Python Tkinter Python Tkinter treview:列大小不会扩展到窗口高度 - Python Tkinter treview: column size does not expand to window height
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM