0

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?

Nae
  • 14,209
  • 7
  • 52
  • 79
patol
  • 136
  • 2
  • 10
  • _"In this case, i don't have any more decoration, but i'm no longer able to access the input fields."_ Do you mean you're unable to use the entry field, `nomEntry`? – Nae Jan 26 '18 at 02:40
  • While above code is simple, you can simplify it more, try to narrow down your code better using [mcve] for improving your question. – Nae Jan 26 '18 at 02:43
  • _"How do I get an operational window without decorations?"_ How exactly is the window in the code that you've provided _not_ operational? – Nae Jan 26 '18 at 02:55
  • 3
    Are you on OSX? – Bryan Oakley Jan 26 '18 at 03:40
  • In linux, window decorations can be removed without using `overrideredirect`, see https://stackoverflow.com/questions/39529600/python-tkinter-remove-titlebar-without-overrideredirect – j_4321 Jan 26 '18 at 11:50
  • tkinter.Tcl().eval('info patchlevel') give '8.6.6' And python 3.6.3 and my os is Mint 18.3 Cinnamon 3.6.7 – patol Jan 26 '18 at 13:06
  • 1
    Do you mean you're unable to use the entry field, nomEntry? **yes** – patol Jan 26 '18 at 13:14
  • I don't think I'm having any trouble with the `nomEntry` using the above code on python 3.6.3, Tk 8.6.6 on Windows 7. – Nae Jan 26 '18 at 18:08

2 Answers2

1

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."

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52
  • tkinter.Tcl().eval('info patchlevel') give '8.6.6' And python 3.6.3 and my os is Mint 18.3 Cinnamon 3.6.7 – patol Jan 26 '18 at 12:59
0

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')
patol
  • 136
  • 2
  • 10