我的问题是使用 .geometry 设置高度和宽度设置窗口内空间的高度和宽度 - 标题栏和窗口边框使其更大。以下是我到目前为止的代码。正如您将看到的,即使我让它创建了一个与可用屏幕区域精确大小的窗口,窗口最终还是太大了,因为在设置大小时没有考虑标题栏和边框。
看到“这里需要改变什么”部分了吗?这两个语句需要更改或替换为什么,很简单?(如果你做对了,窗口应该完全适合桌面上的可用空间,标题栏和边框清晰可见。)
请保持简单 - 我对这一切还是陌生的。:-)
#Important variables:
#screenAvailableWidth, screenAvailableHeight: Height & width of
# screen without
# taskbar
#windowWidth, windowHeight: Height & width of new window to create
#window: Object of class Tk() from tkinter.
#Get screen height and width WITHOUT including the taskbar.
#This part works fine - I've tested the result and it's good.
from win32api import GetMonitorInfo, MonitorFromPoint
monitorInfo = GetMonitorInfo(MonitorFromPoint((0,0)))
workArea = monitorInfo.get("Work")
screenAvailableWidth = workArea[2]
screenAvailableHeight = workArea[3]
#Create a tkinter window
from tkinter import Tk
window = Tk()
#Set new window height & width
#--------------------------------------------
#----- HERE. What needs to change here? -----
#--------------------------------------------
windowWidth = screenAvailableWidth
windowHeight = screenAvailableHeight
#--------------------------------------------
#Show debug info
print("")
print("screenAvailableWidth:",screenAvailableWidth,
" screenAvailableHeight:",screenAvailableHeight)
print("windowWidth:\t",windowWidth," windowHeight:\t",windowHeight)
#Set the new window to upper left corner and height &
# width of screen
window.geometry("{}x{}+0+0".format(windowWidth,windowHeight))
#Show the window
window.mainloop()
呼如林
长风秋雁
拉莫斯之舞
随时随地看视频慕课网APP
相关分类