【发布时间】:2018-01-26 02:36:45
【问题描述】:
在 python 3.6.3 上使用此测试代码
tkinter.Tcl().eval('info patchlevel') 返回'8.6.6'
我的操作系统是 Mint 18.3 Cinnamon 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(),但这并没有改变我的问题:没关系,但有装饰。
如何获得没有装饰的操作窗口?
【问题讨论】:
-
“在这种情况下,我没有更多的装饰,但我不再能够访问输入字段。” 你的意思是你不能使用输入字段,
nomEntry? -
虽然上面的代码很简单,但您可以进一步简化它,尝试使用minimal reproducible example 更好地缩小您的代码范围以改进您的问题。
-
“我如何获得一个没有装饰的可操作窗口?” 您提供的代码中的窗口究竟如何不可操作?
-
你在 OSX 上吗?
-
您的意思是您无法使用输入字段nomEntry? 是的