[Tutor] Text Box

Corey Woodworth cdwom@mpinet.net
Thu, 29 Mar 2001 17:37:11 -0500


> Thanks! I got it working! I'm using it to see if a text item is empty when
> someone chooses Open from the File menu. If it is empty, the file is
opened
> in the current window, otherwise its opened in a new window. It works
fine,
> except for once it creates a new window and puts the file in it, the old
> window becomes the active window (The new one doesn't keep the focus if
that
> makes sense.) Is there a topleve meathod to make a window recieve the
focus,
> or is there just simply a better way to achieve this? Here is my code:
>
>     def openfile(self):
>         pl = END
>         oname = askopenfilename(filetypes=[("Text files", "*.txt")])
>         if len(self.st.get(1.0,END)) == int(1):
>             if oname:
>                 for line in fileinput.input(oname):
>                     self.st.insert(pl,line)
>                 self.t.title("PythonPadTk - "+oname)
>         else:
>             if oname:
>                 neweditor()
>                 for line in fileinput.input(oname):
>                     tl[len(tl)-1].st.insert(pl,line)
>                 tl[len(tl)-1].t.title("PythonPadTk - "+oname)
>
> tl[] is a list of the toplevel widgets, st is a scroll text object and i
> thing the rest is self explainatory.

Sorry for replying to my own post, but I found the awser hidden on the
Python site. I just needed to add a line that says:
tl[len(tl)-1].t.focus()

Still, any help with my previous problems would be helpful:

1. How can add Copy Cut and Paste to an edit menu? I know how to make the
menu items, I just don't know how to assign them to Cut, Copy, and Paste
actions.

2. I know that you can askopenfilename and asksaveas to bring up premade
Open and Save As Dialogue boxes. Is there a similar one for print?

3. How can I add Keyboard shortcuts to menu items? Particuarlt Cut, Copy,
Paste, Save, and Open if they are prebuilt, but I'd also like to know how to
generate my own (for ex. If I added custom menuitem and wanted a shortcut to
it)

Thanks again,

Corey