Python tkinter open new window with prompt button
How can I open a new window by the user by clicking a button in the tkinter GUI? I only need fairly simple solutions and if the code could be explained it would be great.
+3
Eddy loring
source
to share
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
Bryan oakley
source
to share