[英]How to set the root window size to half of the screen width and height Python Tkinter
我試圖獲取用戶監視器大小的寬度和高度。 我可以得到這個,但現在我的主要問題是如何將根窗口設置為寬度廣告高度的一半,但我遇到了一堵牆,我在網上找不到任何可以幫助我的東西,我在這里做錯了什么?
這是代碼:
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry("widthxheight")
我知道它設置為全屏尺寸。 這是我想先做的。
要使窗口全屏大小,請使用:
width = root.winfo_screenwidth()
height = root.winfo_screenheight()
root.geometry(f'{width}x{height}')
要使它成為屏幕尺寸的一半,只需在width
和height
之后放置/2
,如下所示:
root.geometry(f'{width/2}x{height/2}')
對於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.