0

I implemented the code in a new window in tkinter

win = tk.Tk()
def tt():
        print("tt")
win.title("win1")
def com():
    win2 = tk.Toplevel(win)
    win.title("win2")
    Button = tk.Button(win2,text="click",command = tt())
    Button.pack()
    win2.mainloop()
Button = tk.Button(win,text="click",command = com)
Button.pack()
win.mainloop()

When I implemented the code like this, it could not be executed, so I gave the grab_set() option knowing that I had to deactivate the parent.

win2.grab_set()

However, the button in win2 only works when the button is pressed in 'win' and does not work when pressed in win2. What should I do

sangbum
  • 33
  • 3
  • 1
    `command=tt()` calls the function *right now* (during the creation of the Button), and its return value (which is implicitly `None`) becomes the action that is taken when the Button is clicked. Notice the difference in the other Button's `command=` option? Get rid of those parentheses. – jasonharper Dec 24 '21 at 04:53
  • 2
    Also avoid calling `mainloop()` more than once. – acw1668 Dec 24 '21 at 05:00

0 Answers0