I am trying to apply transient
to Tk()
instance. Example:
JavaScript
x
19
19
1
import tkinter as tk
2
3
4
root = tk.Tk()
5
root.geometry('200x200')
6
7
def create_new_window():
8
win=tk.Toplevel()
9
win.transient(root)
10
win.geometry('200x200')
11
tk.Label(win,text=' Hello World ').pack()
12
13
label1 = tk.Label(root, text='Click the button')
14
label1.pack()
15
16
b1=tk.Button(root,text='New Window',command=create_new_window)
17
b1.pack()
18
root.mainloop()
19
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:
JavaScript
1
10
10
1
.
2
label1 = tk.Label(root, text='Click the button')
3
label1.pack()
4
5
root.transient(root)
6
7
b1=tk.Button(root,text='New Window',command=create_new_window)
8
b1.pack()
9
10
I get an error:
JavaScript
1
7
1
Traceback (most recent call last):
2
File "c:/Users/91996/Documents/Visual studio code/cd.py", line 15, in <module>
3
root.transient(root)
4
File "C:Program FilesPython3.8.6libtkinter__init__.py", line 2233, in wm_transient
5
return self.tk.call('wm', 'transient', self._w, master)
6
_tkinter.TclError: can't make "." its own master
7
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:
JavaScript
1
19
19
1
import tkinter as tk
2
3
4
root = tk.Tk()
5
root.geometry('200x200')
6
7
def create_new_window():
8
win=tk.Toplevel()
9
win.attributes('-toolwindow',True)
10
win.geometry('200x200')
11
tk.Label(win,text=' Hello World ').pack()
12
13
label1 = tk.Label(root, text='Click the button')
14
label1.pack()
15
16
b1=tk.Button(root,text='New Window',command=create_new_window)
17
b1.pack()
18
root.mainloop()
19