I am trying to apply transient
to Tk()
instance. Example:
import tkinter as tk root = tk.Tk() root.geometry('200x200') def create_new_window(): win=tk.Toplevel() win.transient(root) win.geometry('200x200') tk.Label(win,text=' Hello World ').pack() label1 = tk.Label(root, text='Click the button') label1.pack() b1=tk.Button(root,text='New Window',command=create_new_window) b1.pack() root.mainloop()
This code will remove the ▭
and -
buttons. But, it will only do it for tk.Toplevel()
:
The window on the left in the root
window and the one on the right is tk.Toplevel()
But is there any way to remove the ▭
and -
buttons on the root window?
When I do:
.... label1 = tk.Label(root, text='Click the button') label1.pack() root.transient(root) b1=tk.Button(root,text='New Window',command=create_new_window) b1.pack() ...
I get an error:
Traceback (most recent call last): File "c:/Users/91996/Documents/Visual studio code/cd.py", line 15, in <module> root.transient(root) File "C:Program FilesPython3.8.6libtkinter__init__.py", line 2233, in wm_transient return self.tk.call('wm', 'transient', self._w, master) _tkinter.TclError: can't make "." its own master
I know I could simply do root.resizable(0, 0)
or root.withdraw()
after-wards. But I am exploring tkinter
and I would like to to see implementation of root.transient()
If soomething obvious is missing, please be gentle.
Thanks a lot in advance!
Advertisement
Answer
This is code:
import tkinter as tk root = tk.Tk() root.geometry('200x200') def create_new_window(): win=tk.Toplevel() win.attributes('-toolwindow',True) win.geometry('200x200') tk.Label(win,text=' Hello World ').pack() label1 = tk.Label(root, text='Click the button') label1.pack() b1=tk.Button(root,text='New Window',command=create_new_window) b1.pack() root.mainloop()