Tkinter new window contentent when button is clicked.

Bischoop Bischoop at vimart.net
Sun Feb 28 06:20:59 EST 2021


On 2021-02-25, MRAB <python at mrabarnett.plus.com> wrote:
>> 
> The trick is to put the "pages" on top of each other and then show the 
> appropriate one, something like this:
> import tkinter as tk
>
> def on_next_page():
>      # Brings page 2 to the top.
>      frame_2.tkraise()
>
> def on_previous_page():
>      # Brings page 1 to the top.
>      frame_1.tkraise()
>
> def on_finish():
>      # Closes the dialog.
>      root.destroy()
>
> root = tk.Tk()
>
> # Page 1.
> frame_1 = tk.Frame(root)
> tk.Label(frame_1, text='Page 1').pack()
> tk.Button(frame_1, text='Next', command=on_next_page).pack()
>
> # Page 2.
> frame_2 = tk.Frame()
> tk.Label(frame_2, text='Page 2').pack()
> tk.Button(frame_2, text='Previous', command=on_previous_page).pack()
> tk.Button(frame_2, text='Finish', command=on_finish).pack()
>
> # Put the pages on top of each other.
> frame_1.grid(row=0, column=0, sticky='news')
> frame_2.grid(row=0, column=0, sticky='news')
>
> # Bring page 1 to the top.
> frame_1.tkraise()
>
> tk.mainloop()


Great, thanks for reply, I'll look into that.


--
Thanks



More information about the Python-list mailing list