tkinter python最大化窗口 [英] tkinter python maximize window
问题描述
我想将一个窗口初始化为最大化,但我不知道如何去做.我在 Windows 7 上使用 python 3.3 和 Tkinter 8.6.我想答案就在这里:http://www.tcl.tk/man/tcl/TkCmd/wm.htm#m8但我不知道如何将它输入到我的 python 脚本中
I want to initialize a window as maximized, but I can't find out how to do it. I'm using python 3.3 and Tkinter 8.6 on windows 7. I guess the answer is just here: http://www.tcl.tk/man/tcl/TkCmd/wm.htm#m8 but I have no idea how to input it into my python script
此外,我需要获取窗口的宽度和高度(最大化以及用户是否在之后重新缩放),但我想我可以自己找出来.
Besides, I need to get the width and height of the window (both as maximised and if the user re-scale it afterwards), but I guess I can just find that out myself.
推荐答案
如果你想把fullscreen属性设置为True,就这么简单:
If you want to set the fullscreen attribute to True, it is as easy as:
root = Tk()
root.attributes('-fullscreen', True)
但是,它不显示标题栏.如果你想让它保持可见,你可以使用 geometry()
方法调整 Tk 元素的大小:
However, it doesn't show the title bar. If you want to keep it visible, you can resize the Tk element with the geometry()
method:
root = Tk()
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.geometry("%dx%d+0+0" % (w, h))
使用 winfo_width()
和 winfo_height()
可以获得宽度和高度或窗口,也可以将事件处理程序绑定到 <配置>
事件:
With winfo_width()
and winfo_height()
you can get the width and height or the window, and also you can bind an event handler to the <Configure>
event:
def resize(event):
print("New size is: {}x{}".format(event.width, event.height))
root.bind("<Configure>", resize)
这篇关于tkinter python最大化窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!