简体   繁体   English

如何在 tkinter 中创建具有全屏宽度/高度的 window?

[英]How to create window with full screen width/height in tkinter?

I'm trying to create a window with full screen size, but not both coordinates, only width or height.我正在尝试创建一个全屏大小的 window,但不是两个坐标,只有宽度或高度。 Some windows in Windows span full height or full width, my window should appear this way. Windows 中的一些 windows 跨越全高或全宽,我的 window 应该是这样出现的。

I tried doing resizable fullscreen mode, but it not what I am looking for.我尝试做可调整大小的全屏模式,但这不是我想要的。 Is there any flag or method to do this?有没有标志或方法可以做到这一点?

edit: i tried using geometry me/thod, state method and attrinbutes method编辑:我尝试使用几何方法、state 方法和 attrinbutes 方法

window.attributes('-fullscreen', True)

It didnt help, cause it doesn't allow you to see Windows toolbar and makes window fullsize by both coordinates, I only need 1 - width ot height它没有帮助,因为它不允许您看到 Windows 工具栏并通过两个坐标使 window 全尺寸,我只需要 1 - 宽度和高度

width = window.winfo_screenwidth()
height = window.winfo_screenheight()
window.geometry("%dx%d" % (width, height/2))

its not so clean, window is a bit unaligned.它不太干净,window 有点未对齐。

window_name.state('zoomed') 

it seems helpful, but state maximizes in both directions, and I don't know if I could easily do the same with 1 direction这似乎很有帮助,但是state在两个方向上都最大化了,我不知道我是否可以在 1 个方向上轻松地做同样的事情

If you want a full screen window, use:如果你想要全屏 window,使用:

win = Tk()
win.attributes('-fullscreen', True)

If you just want it to be full screen in one direction, you can first get the height/width of the screen and then set the window size:如果你只是想让它在一个方向上全屏,你可以先获取屏幕的高度/宽度,然后设置 window 大小:

win = Tk()

screen_width = win.winfo_screenwidth()
screen_height = win.winfo_screenheight()

# replace either screen_width and screen_height to change the appropriate dimension
win.geometry(f"{screen_width}x{screen_height}")
win.mainloop()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM