没有装饰的窗户

2024-04-18 01:08:32 发布

您现在位置:Python中文网/ 问答频道 /正文

在python3.6.3上使用此测试代码

tkinter.Tcl().eval('info patchlevel')返回'8.6.6' 我的操作系统是薄荷18.3肉桂3.6.7,但我希望我的代码是跨平台的。 我使用控制台运行脚本:

from tkinter import *
from tkinter import ttk

def valid(*args):
    print("Dans valid", nom.get())
    root.quit()

root = Tk()

rootW = 300
rootH = 200
x = (root.winfo_screenwidth() - rootW)//2
y = (root.winfo_screenheight() - rootH)//2
root.geometry(f'{rootW}x{rootH}+{x}+{y}')

mainFrame = ttk.Frame(root,  padding="5")
mainFrame.grid(column=0, row=0, sticky=(N, W, E, S))
mainFrame.columnconfigure(0, weight=1)
mainFrame.rowconfigure(0, weight=1)

nom = StringVar()
nomEntry = ttk.Entry(mainFrame,  width=20,  textvariable=nom)
nomEntry.grid(column=2, row=2, sticky=(E))
ttk.Label(mainFrame, text="Inscription").grid(column=2, row=1, sticky=W)
ttk.Label(mainFrame, text="Votre nom").grid(column=1,  row=2)
ttk.Button(mainFrame, text="Validation", command=valid).grid(column=2, row=3, sticky=W)

for child in mainFrame.winfo_children():
    child.grid_configure(padx=5, pady=5)

nomEntry.focus()
#root.update_idletasks()
root.overrideredirect(1)

root.mainloop()
root.destroy()

我想使用一个tkinter窗口,用overrideredirect()方法删除该窗口中的所有窗口管理器装饰。你知道吗

在这种情况下,我没有更多的装饰,但我不再能够访问Entry字段,而"Validation"按钮是可操作的,并退出窗口。你知道吗

如果我评论这行root.overrideredirect(1),一切正常,有装饰。你知道吗

我试着添加一行root.update_idletasks(),但这并没有改变我的问题:没关系,但有装饰。你知道吗

我怎样才能得到一个没有装饰的操作窗口?你知道吗


Tags: tkintercolumn装饰rootnomgridrowttk
2条回答

我想我已经找到了一个解决方案,它在linux上无论如何都是有效的(在windows和OsX上测试)

root = Tk()
root.wm_attributes('-type', 'splash')

当我在3.6.4,tk8.6.6,win10上运行(空闲)时,我看到一个没有装饰的窗口,有两个标签,一个带焦点的输入框和一个按钮。当我输入“thisatest”并单击按钮时,我看到shell中打印了“dansvalidthisatest”。我看没什么问题。你知道吗

NMT tk 8.5文档声称.update_idletasks是必需的,但是对于windows上TK8.6的代码来说似乎不是这样。它还说“这种方法在某些Unix和MacOS平台上可能不起作用”,这适用于您吗?如果您使用的是MacOS,那么您可能运行的是8.5版本,也可能是一个有缺陷的旧版本8.5,可以更新。你知道吗

official tcl/tk 8.6文档提供了更多的技术细节,并且还提到行为依赖于系统(尽管我不了解细节):“一些,但不是全部,平台会在额外的时间注意到。”

相关问题 更多 >

    热门问题