0

How can I change the content of a window, in a GUI application using tkinter? Like when you press the button it show different text or content, replacing the original.

Example:

from Tkinter import *
app = Tk()
app.geometry("500x500")
def page2():
    app2 = Tk()
    app2.geometry("500x500")

Button(app, text="button", command=page2).pack()

app.mainloop()

Window one shows information1 and window 2 shows information2. I want the button to change information1 into information2, instead of open a new window.

How can one turn the first window into the second window without opening a new window?

Jean-François Corbett
  • 37,420
  • 30
  • 139
  • 188
enix
  • 113
  • 1
  • 8
  • Have you tried anything? Do you know how to change the page programatically? Do you know how to catch a key press event? – will Nov 13 '14 at 15:10
  • I'm new to python (know some basic),working on a simple program. Can you please point me out to the topic which can help me? – enix Nov 13 '14 at 15:13
  • What's a page? I don't think that's a type in the tkinter library. – Kevin Nov 13 '14 at 15:15
  • @Kevin so tkinter is not related to this. I will remove the tag – enix Nov 13 '14 at 15:17
  • Could you post some code? Maybe an example to demonstrate what you want to do? – will Nov 13 '14 at 15:18
  • @enix, it's related to the question if that's the GUI library that you're using. Readers at least need to know if you're writing a text-only command line application, or a windowed application with buttons/textboxes/etc, or what. – Kevin Nov 13 '14 at 15:20
  • I tried my best to explain my question. I'm not a native english speaker, if this still unclear please close it. – enix Nov 13 '14 at 15:40
  • @Jean-François Corbett thank for your edit – enix Nov 13 '14 at 16:00
  • You could take a look at [this answer](http://stackoverflow.com/questions/24492295/python-gui-open-a-new-page/24492944#24492944) on another, similar, question. – fhdrsdg Nov 14 '14 at 08:58

1 Answers1

0

The following 3.x version (change 'tkinter' to 'Tkinter' for 2.x) should give you a start.

import tkinter as tk

app = tk.Tk()
app.geometry("500x500")
text = tk.Text(app)
text.pack()
text.insert('insert', 'Page 1')

def page2():
    text.delete('1.0', 'end')
    text.insert('insert', 'Page 2')

tk.Button(app, text="new page", command=page2).pack()

app.mainloop()

For further reading, see the Library manual page and references given at the top, especially 2-4.

Terry Jan Reedy
  • 18,414
  • 3
  • 40
  • 52