tags:

views:

214

answers:

1
from Tkinter import *

root = Tk()
root.title("Whois Tool")

text = Text()
text1 = Text()

text1.config(width=15, height=1)
text1.pack()

def button1():
        text.insert(END, text1)

b = Button(root, text="Enter", width=10, height=2, command=button1)
b.pack()

scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
text.config(width=60, height=15)
text.pack(side=LEFT, fill=Y)
scrollbar.config(command=text.yview)
text.config(yscrollcommand=scrollbar.set)

root.mainloop()

How can I add the data from a text widget to another text widget? for example Im trying to insert the data in text1 to text but it wont work.. text.insert(END, text1)

+2  A: 
def button1():
        text.insert(INSERT, text1.get("1.0", END))

Not an intuitive way to do it in my opinion. 1.0 means line 1, column 0. Yes, the lines are 1-indexed and the columns are 0-indexed. :)

Note that you may not want to import the entire Tkinter package. using from...import. It will likely lead to confusion down the road. I would recommend using:

import Tkinter.
text = Tkinter.Text()

etc. Another option is:

import Tkinter as tk
text = tk.Text()

You can choose a short name (like "tk") of your choice. Regardless, you should stick to one import mechanism for the library.

Matthew Flaschen
I get an error: text.insert(Tkinter.INSERT, text1.get("1.0", Tkinter.END))NameError: global name 'Tkinter' is not defined
sourD
Yeah, I did the imports differently then you while testing. I've fixed the answer, but the way you're doing it can lead to issues.
Matthew Flaschen
and text.get("1.0") only gets the first letter, like if i put "hello" and click the button it will only print out the first letter which is "h" :(
sourD
oops dint see you fixed ur code.. thanks
sourD