Reputation: 136
With this test code on python 3.6.3
tkinter.Tcl().eval('info patchlevel')
returns '8.6.6'
My OS is Mint 18.3 Cinnamon 3.6.7, but I want my code to be crossplatform.
I use the console to run the script:
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()
I want to use a tkinter window that removes all window manager decorations from that window with overrideredirect()
method.
In this case, I don't have any more decoration, but I am no longer able to access the Entry
field, while the "Validation"
button is operational and exits the window.
If I comment the line root.overrideredirect(1)
everything works normally, with decoration.
I tried adding the line root.update_idletasks()
, but it doesn't change my problem: it's ok but with decorations.
How do I get an operational window without decorations?
Upvotes: 0
Views: 404
Reputation: 136
I think I have found a solution, which is in any case valid on linux (to be tested on windows and OsX)
root = Tk()
root.wm_attributes('-type', 'splash')
Upvotes: 0
Reputation: 19174
When I run (with IDLE) on 3.6.4, tk8.6.6, Win 10, I see an undecorated window with two labels, an entry box with focus, and a button. When I enter "this is a test" , and click the button, I see "Dans valid this is a test" printed in the shell. I do not see any problem.
The NMT tk 8.5 doc claims that .update_idletasks
is needed, but it seems not for this code with tk 8.6 on windows. It also says "This method may not work on some Unix and MacOS platforms." Does this apply to you? If you are on MacOS, you are probably running 8.5 and possibly a buggy older 8.5 release that could be updated.
The official tcl/tk 8.6 doc gives a bit more techinical detail, and also mentions that behavior is system dependent (though I do not understand the detail): "Some, but not all, platforms will take notice at additional times."
Upvotes: 1