Is there a function out their in python that you will declare a target i.e. a text box on another open window, and it would print text to that screen? Thanks

Recommended Answers

All 4 Replies

So you want a text box in one window, and what you type in the text box will also show up in another window?

sort of, but for example if you had a open notepad it would print "Hello World!" onto that notepad

So two text boxes, and the text from one goes into the other?

(or do you mean MS Notepad? That would be quite a challenge).

Here's a small example:

import Tkinter as tk

class MyFrame(tk.Frame):

    def __init__(self, parent):
        tk.Frame.__init__(self, parent)
        self.text1 = tk.Text(self, width=40, height=10)
        self.text2 = tk.Text(self, width=40, height=10, state=tk.DISABLED)
        self.text1.grid()
        self.text2.grid()

        self.text1.bind("<Any-KeyPress>", self.copytext)

    def copytext(self, event):
        text = self.text1.get("0.0", tk.END)
        self.text2["state"]=tk.NORMAL
        self.text2.delete("0.0", tk.END)
        self.text2.insert("0.0", text)
        self.text2["state"]=tk.DISABLED

app = tk.Tk()
app.frame = MyFrame(app)
app.frame.grid()
app.mainloop()

It's not perfect -- the second Text widget is one character behind the first because the <Any-KeyPress> event is processed prior to the key being inserted into the first Text.

But it gives a decent idea.

Jeff

thanks for answering my question your code works perfect :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.