python - Tkinter: adding existing content to a frame -


i'm working on simple text based game in python/tkinter, , made basic setup far. displays intro. text, , can type(this still work in progress). however, realized there going lot of text, , thought of frame's scrollbar capability.

however, added current content frame , functions don't work now. following someone's example, don't know if it's right. here code:

from tkinter import *  w=tk() w.configure(background="navy") w.iconbitmap(default="blankicon.ico") w.title("decimated world") w.resizable(0,0)  introtext="when wake, see sky dark; can't tell time of day."  scen1="you head toward town hall."  class app(frame): def __init__(self,w):     frame.__init__(self,w) def key(event):     print event.char  t=text(w) t.insert(insert,introtext) t.configure(state=disabled,background="navy",foreground="white") t.pack()  def do_command(command):     t.configure(state=normal)     t.insert(insert,'\n>>> {}'.format(command))     t.configure(state=disabled)  s=stringvar() e=entry() e.configure(background="navy",foreground="white") e.focus_set() e.pack(side=bottom)  def enter(event):     do_command(e.get())     if e.get()=="walk north":         t.configure(state=normal)         t.insert(insert,"\n"+scen1)         t.configure(state=disabled)  e.bind("<keyrelease-return>",enter)   w.mainloop() 

i'd appreciate anyone's putting existing functions/widgets frame. thanks.

as long text has name can use pack , unpack methods.

for example:

b = label(root, text='click me') b.pack() 

and remove it:

b.pack_forget() 

and when want add again type:

b.pack() 

it simple that!


Comments

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -