0

Hi I had this exact same question :

opening a new window with a button

But as I ran the code given : (EDIT : first line is indeed from tkinter import *)

from tkinter import *

def create_window():
    window = Toplevel(root)

root = Tk()
b = Button(root, text="Create new window", command=create_window)
b.pack()
root.mainloop()

the new window opens automatically, without waiting for the button to be clicked

why is that?

Maff Berr
  • 21
  • 3
  • Cannot be reproduced. – Isma Feb 08 '21 at 20:22
  • e pur si muove! I promise I didn't invent the case... when i run the code,two windows are created. The button creates a new one each time, but i d like just one window to start with – Maff Berr Feb 08 '21 at 20:26
  • There is nothing in this code that will cause two windows to be created at startup. How are you running this code? – Bryan Oakley Feb 08 '21 at 20:28
  • ok I think I got it. Sorry. using Jupyter, and it seems a previous cell was interfering : top=Tk() I didn't think, as it is not the same name, that it would react that way. Thank you for your comments – Maff Berr Feb 08 '21 at 20:34

0 Answers0