Python tkinter open new window with prompt button
1 answer
Here is the shortest possible solution to your question. The solution works in python 2.x. For python 3.x, change the import to "tkinter" and not to "Tkinter":
import Tkinter as tk
def create_window():
window = tk.Toplevel(root)
root = tk.Tk()
b = tk.Button(root, text="Create new window", command=create_window)
b.pack()
root.mainloop()
This is not what I recommend as an example of good coding style, but it does illustrate the basic concepts: a button with a command and a function that creates a window.
+9
source to share