带有标题栏和 Windows 任务栏的 Tkinter 窗口 [英] Tkinter window with both title bar and windows taskbar

查看:45
本文介绍了带有标题栏和 Windows 任务栏的 Tkinter 窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经广泛搜索了这个问题,但似乎没有人知道.我在 python 2.7 中创建了一个简单的 tkinter 窗口(tcl 8.5)并希望它最大化,就像我点击右上角的最大化按钮一样.使用 -fullscreen 选项不是一个选项,因为它删除了标题栏.

I have searched wide and far for this question, but noone seems to know. I create a simple tkinter window (tcl 8.5) in python 2.7 and want it maximized, just as if I would hit the maximize button in top right corner. Using the -fullscreen option is not an option since it removes the title bar.

我尝试了以下方法:

import Tkinter

root = Tkinter.Tk()
root.overrideredirect(True)
# Set window to be size of screen
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))  

问题是窗口现在位于 Windows 任务栏下方,因此我的某些元素未显示.一个简单的技巧是将高度设置为 screenheight-some_constant,或者根据来自操作系统的数据计算 some_constant.然而,这似乎是一个极其丑陋的黑客.

The problem is that the window is now below the Windows taskbar and some of my elements are therefore not shown. An easy hack would be to set height to screenheight-some_constant, or calculate some_constant based on data from the operating system. However, this seems like an extremely ugly hack.

有没有办法以干净的方式最大化 tkinter 中的窗口,其中窗口位于(Windows)任务栏上方并且仍然有标题栏?

Is there any way to maximize a window in tkinter in a clean way where the window is above the (Windows) taskbar and still has a title bar?

推荐答案

我知道这是一个老问题,但我已经使用 TCL 8.5 和 tk 在带有 python 2.7.6 的 XP 系统(32 位)上测试了以下代码8.5 版.

i know this is an old question but i have tested the following code on an XP system (32bit) with python 2.7.6, using TCL version 8.5 and tk version 8.5.

代码:

import Tkinter as tk

root = tk.Tk()

root.state("zoomed")

root.mainloop()

这确实启动了在主监视器上最大化的窗口.
它确实存在缺陷 - 我无法在另一台显示器上使其最大化,但确实可以在不覆盖标题栏或任务栏的情况下可靠地工作.

this does start the window maximised on the primary monitor.
it does have pitfalls - i have been unable to make it maximise on another monitor, but does work reliably without covering the title bar or taskbar.

如果你想保留标题栏,我会省略 overrideredirect.

and as you want to keep the title bar i would leave out the overrideredirect.

这篇关于带有标题栏和 Windows 任务栏的 Tkinter 窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆